This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes on getting loaded...... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "on getting loaded......" Watch "on getting loaded......" New topic
Author

on getting loaded......

Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1195
I'm very unclear on some basic knowledge concerning the JVM and the compiler. My question is this:
Non-static instance variables are initialized just before the class constructor is executed. Is the constructor executed at compile time or run-time? On the same theme, static variables are initialized at class load time. Exactly when does a class get loaded? I am really fuzzy on this subject, and I think I need to understand this before I think about taking any certification exams......
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Constructors, like all code, are executed at runtime. The running JVM allocates RAM for the object, then calls a constructor to initialize that RAM.
A class is generally loaded only when it needs to be -- when a static member is referenced, or an object needs to be created. This lets you write Java code which conditionally calls other code that may or may not exist at runtime.
You might want to check out chapter 12 of the Java Language Specification.


[Jess in Action][AskingGoodQuestions]
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1195
Thanks Ernest. I'm still trying to figure out a lot of the behind the scene activity with the compiler and the JVM. I get sooooooo confused sometimes. I've checked out the link you gave, and it answers a lot of my questions!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: on getting loaded......