When reading the answer to this question, I was wondering how Java7 bootstrap knows about the presence of public static void main(String[] args)
method, without running the static initializers? I have some assumptions on this topic, but some of them is obviously wrong:
- Java Bootstrap is running in JVM, so it can only use standard JVM features (no native features) - the called class must be on CLASSPATH, for example
- The standard JVM classloading is done via the normal classloading mechanism (I know it has several steps, I've been playing with classloaders several times)
- After the class has been resolved (linked), the Class initialization is run immediately (including initializing static attributes and running static initializers)
- There is no way to part the previous two steps
My questions are:
- Who calls the class initializers and in what phase? (what happens before, and what after?)
- Why does the bootstrap behave differently compared to the "normal" classloading? Are there more differences over this?
- Bonus question: Which of my assumptions is wrong?
To summarize the referred question: if you run a Java main class (from Java7 command line), it will check the presence of the main()
method, without running the static initializers. In Java6 it behaves differently.