🚀 Understanding Class Loaders in Java

 



In Java, Class Loaders are part of the JVM responsible for loading classes into memory when they are needed. Without them, your Java code couldn’t run!

🔹 Types of Class Loaders
1️⃣ Bootstrap Class Loader → Loads core Java classes (java.lang.*, java.util.*).
2️⃣ Extension (Platform) Class Loader → Loads classes from lib/ext or platform-specific extensions.
3️⃣ Application (System) Class Loader → Loads classes from the application classpath.

🔹 How Class Loading Works
Follows Parent Delegation Model:
Ask parent to load the class.
If not found, load it yourself.
Ensures core classes aren’t overridden accidentally.

🔹 Why Create a Custom Class Loader?
Custom class loaders are useful when ->
1. You want to load classes dynamically at runtime (e.g., plugins).
2. You need to load classes from non-standard sources (network, encrypted files, DB).
3. You’re building application servers or frameworks that isolate modules.
4. You want hot reloading without restarting the JVM.

Post a Comment

Previous Post Next Post