1.1 ClassLoader Hierarchy & Parent Delegation Model
Module 1: JVM Architecture & Class Loading

1.1 ClassLoader Hierarchy & Parent Delegation Model

Estimated reading & practice time: ~20 minutes

Learning Objectives

• Understand the 3-tier standard ClassLoader hierarchy. • Trace the Parent Delegation model from child to Bootstrap loader. • Diagnose `ClassNotFoundException` vs `NoClassDefFoundError`.

Mental Model & Analogy

The ClassLoader parent delegation model is like asking permission up a corporate ladder: Before a junior clerk (Application Loader) orders a stamp, they must first ask their manager (Platform Loader), who first asks the CEO (Bootstrap Loader). Only if the CEO says 'I don't have this' does the request cascade back down.

Core Concept Breakdown

How the JVM loads `.class` files into memory: 1. **Bootstrap ClassLoader**: Native C++ loader built into JVM core; loads `java.base` classes (`java.lang.Object`, `String`). Calling `String.class.getClassLoader()` returns `null` because it is native. 2. **Platform ClassLoader**: Loads platform extensions and JDK modular packages. 3. **Application (System) ClassLoader**: Loads application classpath and third-party JARs. **Parent Delegation Principle**: A ClassLoader always delegates loading to its parent before attempting to read bytecode itself. This prevents malicious code from replacing `java.lang.SecurityManager` or `java.lang.String`.

Architecture Diagram

Bootstrap Loader Core java.base (C++) Platform Loader JDK Modular Extensions Application Loader Your App & Maven JARs

Code Example

JAVA Example
public class ClassLoaderDemo {
    public static void main(String[] args) {
        // Application ClassLoader
        ClassLoader appLoader = ClassLoaderDemo.class.getClassLoader();
        System.out.println("App Loader:      " + appLoader.getName());

        // Platform ClassLoader
        ClassLoader platformLoader = appLoader.getParent();
        System.out.println("Platform Loader: " + platformLoader.getName());

        // Bootstrap ClassLoader (Native/Null)
        ClassLoader bootstrapLoader = String.class.getClassLoader();
        System.out.println("Bootstrap Loader (Native): " + bootstrapLoader);
    }
}

Line-by-Line Walkthrough

• Demonstrates inspecting class loader parents programmatically. • `String.class.getClassLoader()` returns `null` because Bootstrap is implemented natively in C++.
Expected Console Output
App Loader:      app
Platform Loader: platform
Bootstrap Loader (Native): null

Common Pitfalls & Debugging

• Confusing `ClassNotFoundException` (checked: file not found on classpath) with `NoClassDefFoundError` (fatal error: class was present at compile-time but failed during runtime static initialization).

Try It Yourself — Java Sandbox

Live Execution

Print the ClassLoader name of `java.sql.Date.class` to see if it belongs to Platform or Bootstrap.

Solution.java
Edit the code and click Run Code to verify output directly inside TBLearn.
1
Terminal Output
Click "Run Code" or press Ctrl+Enter to execute.
Knowledge Checkpoint • Earn +40 Credits

Test Yourself Before Moving Forward

Short, practical questions tied directly to this section. Passing awards Credits toward course discounts and interview packs.

Module 1 Checkpoint: JVM ClassLoading & Tiered JIT

Test understanding of class loader delegation hierarchies, C1/C2 JIT compilation, and tiered HotSpot optimization.