|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.ClassLoader
public abstract class ClassLoader
The ClassLoader is a way of customizing the way Java gets its classes and loads them into memory. The verifier and other standard Java things still run, but the ClassLoader is allowed great flexibility in determining where to get the classfiles and when to load and resolve them. For that matter, a custom ClassLoader can perform on-the-fly code generation or modification!
Every classloader has a parent classloader that is consulted before the 'child' classloader when classes or resources should be loaded. This is done to make sure that classes can be loaded from an hierarchy of multiple classloaders and classloaders do not accidentially redefine already loaded classes by classloaders higher in the hierarchy.
The grandparent of all classloaders is the bootstrap classloader, which
loads all the standard system classes as implemented by GNU Classpath. The
other special classloader is the system classloader (also called
application classloader) that loads all classes from the CLASSPATH
(java.class.path
system property). The system classloader
is responsible for finding the application classes from the classpath,
and delegates all requests for the standard library classes to its parent
the bootstrap classloader. Most programs will load all their classes
through the system classloaders.
The bootstrap classloader in GNU Classpath is implemented as a couple of
static (native) methods on the package private class
java.lang.VMClassLoader
, the system classloader is an
instance of gnu.java.lang.SystemClassLoader
(which is a subclass of java.net.URLClassLoader
).
Users of a ClassLoader
will normally just use the methods
loadClass()
to load a class.getResource()
or getResourceAsStream()
to access a resource.getResources()
to get an Enumeration of URLs to all
the resources provided by the classloader and its parents with the
same name.Subclasses should implement the methods
findClass()
which is called by loadClass()
when the parent classloader cannot provide a named class.findResource()
which is called by
getResource()
when the parent classloader cannot provide
a named resource.findResources()
which is called by
getResource()
to combine all the resources with the
same name from the classloader and its parents.findLibrary()
which is called by
Runtime.loadLibrary()
when a class defined by the
classloader wants to load a native library.
Class
Constructor Summary | |
---|---|
protected |
ClassLoader(ClassLoader parent)
Create a new ClassLoader with the specified parent. |
Method Summary |
---|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected ClassLoader(ClassLoader parent)
loadClass()
or getResource()
. Only when the
parent classloader cannot provide the requested class or resource the
findClass()
or findResource()
method
of this classloader will be called. There may be a security check for
checkCreateClassLoader
.
parent
- the classloader's parent, or null for the bootstrap
classloader
java.lang.SecurityException
- if the security check fails
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |