aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes What is Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "What is "class load time" v/s. "class instantiation time" ?" Watch "What is "class load time" v/s. "class instantiation time" ?" New topic
Author

What is "class load time" v/s. "class instantiation time" ?

kishor kotecha
Greenhorn

Joined: Oct 02, 2000
Posts: 27
When it is said ...
"Static variables are initialised to defaults at 'class load time' " and "Instance variable are initialised when the class is instantiated"
what does class load time mean? When is the situation that class is just loaded but not instantiated?
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Let me try..
Loading a class is the process of "bringing into memory" the bytecode representation of the class. Note that loading and initialization of a class can consists of loading/initialization of other classes. The implementation of the VM dictates whether all classes gets loaded once, or a "lazy loading" strategy is used ie., classes are loaded as and when required.
Initialization consists of execution of any class variable initializers and static initializers of the class that has (just)been loaded, in textual order. Initialization of an interface consists of executing the initializers for fields (constants) declared there. Before a class is initialized, its superclass must be initialized, but interfaces implemented by the class are not initialized. Similarly, the superinterfaces of an interface are not initialized before the interface is initialized. The intent here is that a class or interface type has a set of initializers that put it in a consistent state, and that this state is the first state that is observed by other classes
Instantiation consists of creating objects of a particular class in memory. Whenever a new class instance is created, memory space is allocated for it with room for all the instance variables declared in the class type and all the instance variables declared in each superclass of the class type. Instantiation consists of executing instance-initializers and identifying a particular constructor to be called with specified arguments (possibly none) as part of the class instance creation process.
Simple as they may sound, each of these process is complex, governed by a lot of rules and can fail. For more details you may refer JLS Section 12.1 Virtual Machine Start-Up.
Hope that helps
Ajith
[This message has been edited by Ajith Kallambella (edited October 03, 2000).]


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
kishor kotecha
Greenhorn

Joined: Oct 02, 2000
Posts: 27
Thanks Ajith. Frankly I was not expecting this kind of fast response. I am thrilled at the fast responses and this Saloon seems very useful. this is only my second or third question on Saloon and I am happy to say I am getting addicted to it. Though your answer is best at what can be the best, I will need to understand that. Useful stuff for understanding basics. and what is the JLS thing you said in reply?
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Kishor,
The JLS Ajith is referring to is the Java Language Specification. It's the Java Bible . You can access an on-line copy of it
here.
Hope that helps
------------------
Jane


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
jQuery in Action, 2nd edition
 
subject: What is "class load time" v/s. "class instantiation time" ?