The best place to ask programming/development questions, imo. UPDATE: stackoverflow is the *worst* place to *ask* questions (if your first question/comment doesn't get any up-rating/response, then u can't ask anymore questions--ridiculously unrealistic), but a great reference for finding answers.

My Music (Nickleus)


test class demonstrating how java 7's JVM processes class initialization and instantiation

Just wrote a java class to demonstrate JVM 7's class initialization processing order

click the link above to go to the source code.

i created a java class with a "main" method, some static variables and some normal (non-static) instance variables, then ran this file with debug breakpoints on all lines of code to find the processing order and here's what i found:

* access modifiers for variables and methods (private, public, protected, etc) don't seem to affect processing order, ALTHOUGH the "main" method must have the "public" modifier

* standard getter and setter methods for variables don't get processed, i.e. debugger never stops on their breakpoints

* "static final" variables don't get processed by the JVM during initialization or instantiation of the class, i.e. debugger never stops on their breakpoints

processing order:
1. static variables and static initialization blocks, in textual order of appearance
2. "main" method:
    2.1 begin executing any logic encountered
        2.1.1 if a call to instantiate the containing class is made (i.e. "new JVMClassInitializationProcessingOrderTest()"), temporarily pause execution of "main" method logic
   initialize (non-static) instance variables and (non-static) initialization blocks, in textual order of appearance
   process the class' constructor
   resume execution of the remaining logic in the "main" method

No comments:

Post a Comment