...
The classes are loaded at that moment, when there are needed for the first time. Not earlier.
Static classes an that containing static methods are instantiated on application startup and are not effected by this rule.
When a class is needed, the class loader loads the class and then it's linked:
There are three phases in the linking process:
- Verification (Checking format and suitability of this JVM)
- Preparation ( Memory allocation etc.)
- Resolution (Recursive loading and linking of classes needed by the resolved class)
After that the classes are initialized( static and as needed) and are executed.
When all non-daemon threads are done, the application terminates.
Class Loader Hierarchy
Instrumentation
...