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
2.1.1.1 initialize (non-static) instance variables and (non-static) initialization blocks, in textual order of appearance
2.1.1.2 process the class' constructor
2.1.1.3 resume execution of the remaining logic in the "main" method
IT, computer and programming tutorials and tips that i couldnt find anywhere else using google, from my daily work as a Senior Developer of solutions using Java and Linux.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment