• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
kishor kotecha
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic