Class Loaders in Java programming language provides a way to
load Java classes into the memory. The Class Loaders are important and powerful
tool in JVM, which loads Java classes into memory when required. The Java class
is loaded for the very first time when JVM calls public static void main(String
[] args) method present in Java class file to load at runtime. All the classes
referenced by the main class are than loaded when needed. A class loader than
creates a namespace for the java classes loaded and already running into the
JVM.
There can be many class loaders running into a JVM whose
main purpose is to provide and loads the class at the runtime. All JVM running
in a environment must have at least one Java Class Loader which is called as
bootstrap class loader (primordial), embedded into an JVM. There are also
non-primordial class loaders too. The JVM also provides user defined class
loaders, which can be used in place of primordial class loaders.
There are various class loaders created by JVM itself which
are as follows :
1. Bootstrap Class Loader : This is most powerful class
loader that JVM uses to load JDK's internal classes, such as java.* packages.
The jar loaded by these class loader such as rt.jar and i18n.jar. This class
loader is not reloadable.
2. Extensions Class Loader : This class loader comes after
Bootstrap Class Loader. This class loader is
powerful, that JVM uses to load jars from JDK extensions directory i.e.
from lib/ext folder of the JRE. This class loader is not reloadable.
3. System Class Loader : This class loader comes after
Extensions Class Loader. This class loader is
powerful, that JVM uses to load jars from system classpath. This is
loaded by setting CLASSPATH environment variable. This class loader is not
reloadable
JVM class loaders use delegation model when loading java
classes. They are hierarchical in nature which means child loaders asks their
parent class loader to load classes before they start loading the classes. So
doing this maintains the uniqueness in class loading and no classes are loaded
twice in JVM.