Step 1. Loading of the class. Throws subclasses of LinkageError ex. ClassFormatError, NoClassDefFoundError.
Step 2. Linking of the class:
The process of taking a binary form of a class or interface type and combining it into the runtime state of the Java virtual machine,
a. Verification – instruction code is verified.
b. Preparation – static variables and method tables are created .
c. Resolution – Checking symbolic references from loaded class to other classes. Resolution translates the names into explicit references.Also checks for field/method existence and whether access is allowed.
Step 3. Initialization of the static variables and initializers.Note that the static variables have already been created during the Preparation phase.
Step 4. main(..) is executed.
Step 5. A class or interface may be unloaded if and only if its class loader is unreachable.
Step 6. The Java virtual machine terminates all its activity and exits when one of two things happens:
- All the threads that are not daemon threads terminate.
- Some thread invokes the exit method of class Runtime or class System, and the exit operation is permitted by the security manager.