Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class loading

 
sreedhar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does a non-static method gets loaded into the memory, when a static method is called on the class (assumption is that there are no objects instatiated)?
 
Mahesh Bhatt
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi sreedhar ,

your question is not very clear to me. however, i am giving the following explanation,I guess it helps you.

static methods belong to the class and not any instance of the class, static code in a class is executed only once, when the class is initialized. and unless u create an instance, ie.. an object, u cannot use the non-static methods of the class. Anything in a class that is declared static is executed when the class is loaded.

I hope it helps..
 
Mahesh Bhatt
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you might like to use the -verbose option . try to use it and go through the output that this option gives you..

all the best ..
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JVM loads a class either when the first instance of that class is created or the first time a static member of that class is referenced (even if an instance is never actually created).

So if there are no instances of that class, then calling one of its static methods will load the class.

When a class is loaded, the entire class file is loaded. At that time, static variables are initialized and static blocks of code are executed. Non-static members are initialized only if an instance is created -- but, again, the entire class loads at one time.
[ September 18, 2004: Message edited by: marc weber ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sreedhar,

Welcome to JavaRanch!

We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.

We request that display names follow the pattern FIRST_NAME + SPACE + LAST_NAME.

Thanks Pardner! Hope to see you 'round the Ranch!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Intermediate forum...
 
Purushoth Thambu
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Loading is the first step in any execution. So when JVM loads the class it won't analyze to see what method is called and what isn't. It will load the entire class definition including static + member methods. Hope this answers your question.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic