Skip to lesson

The bootstrap, platform and application class loaders

Every JVM since Java 9 starts with three built-in class loaders: bootstrap, platform and application. Each one loads a different group of classes, and getClassLoader() tells you which one loaded a given class.

Bootstrap loader for core classes such as java.lang.String

The bootstrap class loader is built into the JVM itself. It loads the most basic classes: java.lang.Object, String, Integer, ArrayList, HashMap, LocalDate and the rest of the java.base module, plus some other core JDK modules.

Example 1 · Core classes come from the bootstrap loader

CoreClassesDemo.javaJava
import java.time.LocalDate;import java.util.ArrayList;import java.util.HashMap;
public class CoreClassesDemo {    static String loaderOf(Class<?> c) {        ClassLoader loader = c.getClassLoader();        return loader == null ? "bootstrap (null)" : loader.getName();    }
    public static void main(String[] args) {        Class<?>[] core = {Object.class, String.class, Integer.class,                           ArrayList.class, HashMap.class, LocalDate.class};        for (Class<?> c : core) {            System.out.println(c.getName() + " -> " + loaderOf(c));        }    }}
Output
java.lang.Object -> bootstrap (null)
java.lang.String -> bootstrap (null)
java.lang.Integer -> bootstrap (null)
java.util.ArrayList -> bootstrap (null)
java.util.HashMap -> bootstrap (null)
java.time.LocalDate -> bootstrap (null)

What this code does

  • Every class here is in the java.base module, which the bootstrap loader handles, so getClassLoader() returns null for all of them.
  • loaderOf checks for null before calling getName(). Without that check the first line would already throw a NullPointerException.

In HotSpot the bootstrap loader is written in native code (C++), not in Java. So there is no Java object for it, and Java shows it as null. It must exist before any Java class loader can work: a class loader is itself a Java class, and someone has to load java.lang.ClassLoader first.

Platform loader (Java 9 and later, replaces the extension loader)

The platform class loader loads the JDK modules that are not handled by the bootstrap loader, such as java.sql (JDBC) and java.net.http (the HTTP client). It is a normal Java object named platform.

Example 2 · Fee receipt: one class from each loader

FeeReceipt.javaJava
import java.sql.Date;import java.time.LocalDate;
public class FeeReceipt {    static String loaderOf(Class<?> c) {        ClassLoader loader = c.getClassLoader();        return loader == null ? "bootstrap" : loader.getName();    }
    public static void main(String[] args) {        LocalDate paidOn = LocalDate.of(2025, 7, 15);        Date forDatabase = Date.valueOf(paidOn);        System.out.println("Fee paid on " + forDatabase);
        System.out.println("LocalDate  -> " + loaderOf(LocalDate.class));        System.out.println("sql.Date   -> " + loaderOf(Date.class));        System.out.println("FeeReceipt -> " + loaderOf(FeeReceipt.class));    }}
Output
Fee paid on 2025-07-15
LocalDate  -> bootstrap
sql.Date   -> platform
FeeReceipt -> app

What this code does

  • java.sql.Date belongs to the java.sql module, which the platform loader handles on JDK 21. LocalDate is in java.base, so it comes from the bootstrap loader.
  • FeeReceipt is your class, found on the class path, so the application loader app defines it. One small program uses all three built-in loaders.

Example 3 · Where each class came from, in the load log

Terminal
javac FeeReceipt.javajava -Xlog:class+load FeeReceipt | grep -E "FeeReceipt|LocalDate |sql.Date"
Sample output
[0.119s][info][class,load] FeeReceipt source: file:/C:/.../fee/
[0.120s][info][class,load] java.time.chrono.ChronoLocalDate source: shared objects file
[0.120s][info][class,load] java.time.LocalDate source: shared objects file
[0.143s][info][class,load] java.sql.Date source: jrt:/java.sql

What this code does

  • A real run on JDK 21 with the folder path shortened; on Windows use findstr with each word instead of grep -E. Times differ per run.
  • The source shows the loader's world: your class from a folder on the class path, LocalDate (and ChronoLocalDate, which the pattern also matches) from the JDK's CDS archive, and java.sql.Date from the java.sql module inside the JDK image (jrt:).

Up to Java 8 this second loader was the extension class loader, which loaded any JAR copied into the JRE's lib/ext folder. Java 9 removed this mechanism when it added the module system, and the platform loader took its place. Which JDK module goes to which loader is a JDK detail, and it can change between versions. The examples here were checked on JDK 21.

Old setup guides that say "copy the JAR into jre/lib/ext" do not work on Java 9 and later. Put the JAR on the class path instead.

Application loader for your class path and module path

The application class loader (also called the system class loader) loads your own classes and every library on the class path (-cp) or the module path. Its name is app, and ClassLoader.getSystemClassLoader() returns it.

Example 4 · Walking up the parent chain

ParentChainDemo.javaJava
class StudentPortal {}
public class ParentChainDemo {    public static void main(String[] args) {        ClassLoader loader = StudentPortal.class.getClassLoader();        System.out.println("StudentPortal was loaded by: " + loader.getName());
        while (loader != null) {            ClassLoader parent = loader.getParent();            String parentName = (parent == null) ? "bootstrap (null)" : parent.getName();            System.out.println(loader.getName() + " -> parent: " + parentName);            loader = parent;        }
        boolean same = ClassLoader.getSystemClassLoader() == StudentPortal.class.getClassLoader();        System.out.println("System class loader is app: " + same);        System.out.println("Platform loader name: " + ClassLoader.getPlatformClassLoader().getName());    }}
Output
StudentPortal was loaded by: app
app -> parent: platform
platform -> parent: bootstrap (null)
System class loader is app: true
Platform loader name: platform

What this code does

  • The loop follows getParent() until it reaches null: app, then platform, then the bootstrap loader, which has no Java object.
  • ClassLoader.getSystemClassLoader() and ClassLoader.getPlatformClassLoader() (Java 9+) give direct access to the two Java-side built-in loaders.

The three loaders form a chain through getParent(): the parent of app is platform, and the parent of platform is the bootstrap loader, shown as null. The Parent Delegation lesson shows how a loader uses this chain. On Java 9 and later the application loader is no longer a URLClassLoader. Old code that casts ClassLoader.getSystemClassLoader() to URLClassLoader fails with a ClassCastException.

getClassLoader() and why it returns null for core classes

getClassLoader() is a method of Class that returns the loader that defined the class. For classes from the bootstrap loader it returns null, because that loader has no Java object.

Example 5 · Mistake: calling getName() on a null loader

LoaderNameDemo.javaJava
import java.util.ArrayList;
class Marksheet {}
public class LoaderNameDemo {    static String unsafeName(Class<?> c) {        return c.getClassLoader().getName();    }
    static String safeName(Class<?> c) {        ClassLoader loader = c.getClassLoader();        return loader == null ? "bootstrap" : loader.getName();    }
    public static void main(String[] args) {        Class<?>[] classes = {Marksheet.class, ArrayList.class};
        for (Class<?> c : classes) {            try {                System.out.println(c.getSimpleName() + ": " + unsafeName(c));            } catch (NullPointerException e) {                System.out.println(c.getSimpleName() + ": NullPointerException");                System.out.println("  " + e.getMessage());            }        }
        System.out.println("Safe version:");        for (Class<?> c : classes) {            System.out.println(c.getSimpleName() + ": " + safeName(c));        }    }}
Output
Marksheet: app
ArrayList: NullPointerException
  Cannot invoke "java.lang.ClassLoader.getName()" because the return value of "java.lang.Class.getClassLoader()" is null
Safe version:
Marksheet: app
ArrayList: bootstrap

What this code does

  • unsafeName works for your own class but crashes for ArrayList, whose loader is null. The message is a helpful NullPointerException text, shown by default since Java 15.
  • safeName checks for null first and reports bootstrap. Any logging or debugging code that prints loaders needs this check.

So String.class.getClassLoader().getName() throws a NullPointerException. Any code that prints or uses a loader must check for null first.

  • Array classes report the loader of their element type: Marksheet[].class gives app, String[].class gives null.
  • Primitive types such as int.class and arrays of them such as int[].class also give null.
  • getName() on a loader (Java 9+) returns app or platform; custom loaders return whatever name they were given, or null.

Next step

Check your understanding

11 quick questions