Class loaders in Java, types of class loader

Classloader: Class loaders are responsible to load the classes during run-time dynamically to the JVM also they are part of JRE. Hence the JVM doesn’t need to know the underlying file system to run the Java program, thanks to class loaders.

Because all classes are only loaded into the memory when it is required by the application. This is where class loaders come into the picture. They are responsible to load the classes into memory.

Class Loader in java

@PC Oracle Doc

Type of Class loaders:

  • Bootstrap class loader
  • Extension class loader
  • application or System class loader

Bootstrap class loader:

All the Java classes loaded by an instance of java.lang.Classloader. However, Class loaders are classes themselves. So the question is who loads the Classloader then.?

This is where the Bootstrap or primordial class loader shows its power. It is the parent class loader for all the other class loaders. It is responsible to load JDK internal classes typically rt.jar and other core libraries located inside the $JAVA_HOME/jre/lib.

The bootstrap class loader is part of the core JVM and written in native code.

Extension class loader:

The extension class loader is a child of the bootstrap class loader and parent of the Application or System class loader. It takes care of loading the extensions of the standard core Java classes so that it’s available to all applications running on the platform.

Extension class loader loads from the JDK extensions directory, usually $JAVA_HOME/lib/ext directory or any other directory mentioned in the java.ext.dirs system property.

Application or System Classloader:

The system or application class loader, on the other hand, takes care of loading all the application level classes into the JVM. It loads files found in the classpath environment variable, -classpath or -cp command-line option. Also, it’s a child of the Extensions class loader.

Recommended Read

Favor composition over inheritance Effective Java


Oracle Doc

Happy Learning !!

Leave a Comment