JVM-ClassLoader
Class Loader Subsystem ensures that classes are loaded safely, lazily, and hierarchically, enabling Java’s security, modularity, and runtime flexibility.
Why we need JVM
JVM is responsible for making Java program Platform Independent,
We write a Java Code (.java) --then--> compiler (javac) --compile it and create --> Byte
Code (.class) --then--> Java Interpreter convert into machine code
How JAVA Runs the Application
JVM Architecture
Think of JVM as 4 major pillars:
1️⃣ Class Loader Subsystem
2️⃣ Runtime Data Areas (Memory)
3️⃣ Execution Engine
4️⃣ Native Interface & Libraries
Class Loader Subsystem
- Loading
- Linking
- Initialization
What Loading does
JVM locates and reads a .class files and create an in-memory representation of that class.
When JVM sees a reference like:
new User();
Then:
- It finds the fully qualified class name
- Asks a class loader to load it.
- Reads bytecodes from:
- File System
- JAR
- Network (rare)
- Stores class metadata into MetaSpace
Types of Class Loader
It follows parent delegation model:
-
Bootstrap or Priomordial → serves as the parent of all the other ClassLoader instances and it is for loading JDK internal classes; eg. java.lang.*, java.util.*
-
Extension or Platform (from Java9) → child of the bootstrap class loader and takes care of loading the standard core java classes; eg. java.sql, java.xml
-
Application or System → child of the extension class loader and load your application-level classes;
new MyClass()is used- A static method is called
- A static field is accessed
- The class is explicitly loaded using:
- Class.forName("MyClass");
.class not found- Class was present during compile
- Missing at runtime
How do we manage / control this?
Developer actions
- Correct classpath
- Dependency management (Maven/Gradle)
- Avoid circular dependencies
What Linking does
Linking has 3 sub-steps
Verify
What happens?
JVM checks:
- Binary representation is structurally correct
- .class file is generated by valid compiler
- .class file is formatted properly
- Illegal memory access
WHY?
- Prevent malicious or corrupted bytecode
- Ensure JVM safety
Prepare
What happens?
- Static variable or Class leve variables are allocated memory
- Default values are assigned to the variables
Resolution - Optional
What happens?
- Symbolic references replaced with direct references
- Method calls linked to actual implementations
- During linking
- Or lazily at runtime
What Initialization does
- In this phase all allocated static variables are assigned with actual values defined in code.
- Class variables are assigned with their original values
- Static block execution in top to bottom or child to parent manner
WHY Initialization Is Separate
- Allows lazy class loading
- Improves startup performance
- Avoids unnecessary execution

Comments
Post a Comment