Tuesday, March 2, 2010

Java Class Loader

             The Java Classloader is a part of the Java Runtime Environment that dynamically loads Java classes into the Java Virtual Machine. Usually classes are only loaded on demand. The Java run time system does not need to know about files and file systems because of class loaders. Delegation is an important concept to understand when learning about class loaders.


              When the JVM is started, three class loaders are used:
                            1) Bootstrap class loader
                            2) Extensions class loader
                            3) System class loader

The bootstrap class loader loads the core Java libraries (/lib directory). This class loader, which is part of the core JVM, is written in native code.
The extensions class loader loads the code in the extensions directories (/lib/ext or any other directory specified by the java.ext.dirs system property). It is implemented by the sun.misc.Launcher$ExtClassLoader class.
The system class loader loads code found on java.class.path, which maps to the system CLASSPATH variable. This is implemented by the sun.misc.Launcher$AppClassLoader class.