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?
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).
Joined: Oct 02, 2000
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?