Java Reference
In-Depth Information
methods
getContextClassLoader
and
setContextClassLoader
allow you to
get and set the context class loader.
16.13.1. The
ClassLoader
Class
A class loader can delegate responsibility for loading a class to its
parent
class loader.
The parent class loader can be specified as a constructor
argument to
ClassLoader
:
protected
ClassLoader()
Creates a class loader with an implicit parent class loader of
the system class loader, as returned by
getSystemClassLoader
.
protected
ClassLoader(ClassLoader parent)
Creates a class loader with the specified parent class loader.
A generic class loader, intended for use by others, should provide both
forms of constructor to allow an explicit parent to be set.
The system class loader is typically the class loader used by the virtual
machine to load the initial application class. You can get a reference to
it from the static method
getSystemClassLoader
.
The
bootstrap
class loader is the class loader used to load those classes
belonging to the virtual machine (classes like
Object
,
String
,
List
, and
so forth). These classes are often referred to as
system classes,
a term
which can lead to some confusion since the system classes are loaded
by the bootstrap loader, whereas application classes are loaded by the
system class loader. The bootstrap loader may or may not be repres-
ented by an actual
ClassLoader
object, so invoking
getClassLoader
on an
instance of one of the system classes will typically return
null
, indicating
it was loaded by the bootstrap loader.