The bootstrap, platform and application class loaders
35 min · Intermediate
Need help? Ask a tutor on WhatsApp (opens in a new tab)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
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)); } }}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.basemodule, which the bootstrap loader handles, sogetClassLoader()returnsnullfor all of them. loaderOfchecks fornullbefore callinggetName(). Without that check the first line would already throw aNullPointerException.
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
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)); }}Fee paid on 2025-07-15 LocalDate -> bootstrap sql.Date -> platform FeeReceipt -> app
What this code does
java.sql.Datebelongs to thejava.sqlmodule, which the platform loader handles on JDK 21.LocalDateis injava.base, so it comes from the bootstrap loader.FeeReceiptis your class, found on the class path, so the application loaderappdefines it. One small program uses all three built-in loaders.
Example 3 · Where each class came from, in the load log
javac FeeReceipt.javajava -Xlog:class+load FeeReceipt | grep -E "FeeReceipt|LocalDate |sql.Date"[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
findstrwith each word instead ofgrep -E. Times differ per run. - The
sourceshows the loader's world: your class from a folder on the class path,LocalDate(andChronoLocalDate, which the pattern also matches) from the JDK's CDS archive, andjava.sql.Datefrom thejava.sqlmodule 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.
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
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()); }}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 reachesnull:app, thenplatform, then the bootstrap loader, which has no Java object. ClassLoader.getSystemClassLoader()andClassLoader.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
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)); } }}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
unsafeNameworks for your own class but crashes forArrayList, whose loader isnull. The message is a helpfulNullPointerExceptiontext, shown by default since Java 15.safeNamechecks fornullfirst and reportsbootstrap. 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[].classgivesapp,String[].classgivesnull. - Primitive types such as
int.classand arrays of them such asint[].classalso givenull. getName()on a loader (Java 9+) returnsapporplatform; custom loaders return whatever name they were given, ornull.
Next step
Check your understanding
11 quick questions