What is Classloader?

It is a component of the Java Runtime Environment that allows the Java Virtual Machine to dynamically load class files (JVM). When a java file is run, the classloader is triggered.

In Java, there are three different types of classloaders:

  • Bootstrap Classloader: The bootstrap classloader is a superclass of extension classloader that loads the standard JDK files from rt.jar as well as other essential classes. The rt.jar file contains all of the java.lang, java.util, java.sql, and other package classes.

  • Extension Classloader: The extension classloader is the child of the Bootstrap classloader and the parent of the System classloaders. It only loads files from the extension classpath, which is located in the ‘ext.dirs/JRE/lib/ext directory. The extension classloader will delegate the file to the System classloader if it is not found in the specified directory.

  • System/Application Classloader: It loads application-specific classes via the environment variable -classpath or the command-line option -cp. If the class is not found in the application classpath, the application classloader throws a ClassNotFoundException.

Classloader is a part of the JRE(java runtime environment) that dynamically load java classes into the java virtual machine (JVM) on demand.

Type of java classloader are three

  1. Bootstrap Class Loader – It loads JDK internal classes, typically loads rt.jar and other core classes for example java.lang.* package classes
  2. Extensions Class Loader – It loads classes from the JDK extensions directory, usually lib/ext directory of the JRE.
  3. System Class Loader –Loads classes from system classpath, that can be set while invoking a program using -cp or -classpath command line options.