Class loading in the JVM is done dynamically as classes are needed during program execution to conserve memory and avoid unnecessary preparation.
The JVM utilizes class loaders in a hierarchical structure including Bootstrap, Platform, and Application ClassLoaders to locate and load classes.
Parent delegation is a pattern where the JVM asks parent class loaders first before child loaders when loading classes to prevent duplication.
Class loading can be delayed until a class is used, enabling the JVM to optimize startup times and memory consumption.
Loading involves finding and reading the .class file into memory, but it does not yet initialize the class or set up static fields.
Linking is the phase where the JVM checks the class structure, verifies bytecode safety, prepares static fields, and resolves symbolic references.
Verification ensures the bytecode follows JVM rules for safety and type correctness, detecting errors like improper type conversions.
Preparation allocates memory for static fields with default values without executing static initialization code.
Resolution converts symbolic references to direct pointers during linking, enhancing runtime performance by replacing name lookups with quick memory access.
Initialization runs static initializers, assigns values to static fields, and ensures class readiness for program execution.