• 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

loaded vs instantiated

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure what the difference is between
"a class is loaded" and "class is instantiated"
Any help is greatly appreciated. Thanks.
-Jay
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A class is loaded when a Java program referencing that class is executed. Its static variables and static blocks are executed at this time. Static variables can be accessed immediately by the program (in the first line of the main method, if necessary).
A class is instantiated when, during a program, an instance of that class is created. At this time instance variables, non-static blocks, and finally the constructor are all executed. Instance variables cannot be accessed until an instance of the class is created.
 
Jay Kay
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Scott.
 
Scott Appleton
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jay, I have to clarify (or maybe even correct) the first part of my statement.
A class is loaded when a statement referencing that class is executed (not necessarily when the program is first started).
This could either be when an instance of that class is first created (all static blocks will execute first), or when a static member of that class is referenced.
The class containing the main() method, of course, is loaded before the main method can run.
Sorry for the inaccuracy of the initial post.
reply
    Bookmark Topic Watch Topic
  • New Topic