Results 1 to 9 of 9

Thread: Core java

  1. #1

    Question Core java

    Hi My question is What is static method in java?


  2. #2
    Expert Member
    Join Date
    Apr 2007
    Answers
    500

    Re: Core java

    Static methods use no instance variables of any object of the class they are defined in. If you define a method to be static, you will be given a rude message by the compiler if you try to access any instance variables. You can access static variables, but except for constants, this is unusual. Static methods typically take all they data from parameters and compute something from those parameters, with no reference to variables. This is typical of methods which do some kind of generic calculation. A good example of this are the many utility methods in the predefined Math class


  3. #3
    Junior Member
    Join Date
    Dec 2007
    Answers
    3

    Re: Core java

    Static methods are executed before creating of object.so,instance variables will not be available to static methods,only static variables will be available.The execution series is first Static Block ,second Static Method Then Any other methods.
    We will define main method as static because with out creating object we cannot call any method and with out main method we can not create object.so we are defining main method as static.


  4. #4
    Junior Member
    Join Date
    Dec 2007
    Answers
    4

    Thumbs up Re: Core java

    nice question.....

    For every class....for it to be executed it needs some memory in the RAM.
    So,as soon as JVM encounters a new class name..it needs the information of the class before an object for the class is created.
    So, as soon as it encounters a new class name...the JVM creates the context(some memory for the class known as "context") of the class.
    in this context of the class,
    the JVM loads all the static information that is present in the class.. i.e., static variables,static methods and static blocks are placed into this context.

    bcoz of this special memory of the class...as already all the static methods,fields and blocks are available.. JVM don't need any object to call this methods or fileds.
    hence we can also refer static methods,fields using the class name.

    and the answer to the question is that the static methods need not to be called using the object.so before creating the object also we can access static methods.

    The requirement to go for the static methods is the same.


  5. #5

    Re: Core java

    nice explanation


  6. #6
    Junior Member
    Join Date
    Dec 2007
    Answers
    3

    Re: Core java

    Hello Geeks users ,i am a new user
    please let me join with u people


  7. #7
    Junior Member
    Join Date
    Nov 2007
    Answers
    1

    Re: Core java

    hello can u explain what is thread?


  8. #8
    Junior Member
    Join Date
    Dec 2007
    Answers
    2

    Thumbs up Re: Core java

    static method is a method for which we need not create an object . we can invoke this by using class reference .of course you can call it by using object.
    static methods are initialized when the source code is loaded in jvm i.e. before creating an object.

    code:
    class Name{
    static void call(){
    S.o.p("----");
    }
    public static void main(String args[]){
    Name n;
    n.call();//here we have called it before creating an object
    }
    }


  9. #9
    Junior Member
    Join Date
    Dec 2007
    Answers
    2

    Re: Core java

    Thread is a dispatchable unit of work.
    or u can say execution of a block of statements in a program.
    ex:
    void display(){
    -----------//statement1
    -----------//statement2
    -----------//statement3
    -----------//statement4
    }

    we can say the above 4 statements executes under a thread.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact