This class is the abstract
superclass of objects that know how to load Java classes into a Java
VM. Given a ClassLoader object, you can
dynamically load a class by calling the public loadClass(
) method, specifying the full name of the desired class.
You can obtain a resource associated with a class by calling
getresource( ), geTResources(
), and getresourceAsStream( ).
Many applications do not need to use
ClassLoader directly; these applications use the
Class.forName( ) and Class.getResource(
) methods to dynamically load classes and resources using
the ClassLoader object that loaded the application
itself.
In order to load classes over the
network or from any source other than the class path, you must use a
custom ClassLoader object that knows how to obtain
data from that source. A java.net.URLClassLoader
is suitable for this purpose for almost all applications. Only rarely
should an application need to define a ClassLoader
subclass of its own. When this is necessary, the subclass should
typically extend java.security.SecureClassLoader
and override the findClass( ) method. This method
must find the bytes that comprise the named class, then pass them to
the defineClass( ) method and return the resulting
Class object. In Java 1.2 and later, the
findClass( ) method must also
define the Package
object associated with the class, if it has not already been defined.
It can use getPackage( ) and
definePackage( ) for this purpose. Custom
subclasses of ClassLoader should also override
findResource( ) and findResources(
) to enable the public geTResource( )
and getresources( ) methods.
In Java 1.4 and later you can specify whether the
classes
loaded through a ClassLoader should have
assertions
(assert statements) enabled.
setDefaultAssertionStatus(
) enables or disables assertions for all loaded
classes. setPackageAssertionStatus(
) and setClassAssertionStatus(
) allow you to override the default assertion
status for a named
package or a named class.
Finally, clearAssertionStatus(
) sets the default status to
false and discards the assertions status for any
named packages and classes.
public abstract class
ClassLoader {
// Protected Constructors
protected
ClassLoader ( );
1.2 protected
ClassLoader (ClassLoader
parent );
// Public Class Methods
1.2 public static ClassLoader
getSystemClassLoader ( );
1.1 public static java.net.URL
getSystemResource (String
name );
1.1 public static java.io.InputStream
getSystemResourceAsStream (String
name );
1.2 public static java.util.Enumeration<java.net.URL>
getSystemResources (String
name )
throws java.io.IOException;
// Public Instance Methods
1.4 public void
clearAssertionStatus ( ); synchronized
1.2 public final ClassLoader
getParent ( );
1.1 public java.net.URL
getResource (String
name );
1.1 public java.io.InputStream
getResourceAsStream (String
name );
1.2 public java.util.Enumeration<java.net.URL>
getResources (String
name ) throws
java.io.IOException;
1.1 public Class<?>
loadClass (String
name ) throws ClassNotFoundException;
1.4 public void
setClassAssertionStatus (String
className , boolean
enabled ); synchronized
1.4 public void
setDefaultAssertionStatus (boolean
enabled ); synchronized
1.4 public void
setPackageAssertionStatus (String
packageName , boolean
enabled ); synchronized
// Protected Instance Methods
5.0 protected final Class<?>
defineClass (String
name , java.nio.ByteBuffer
b ,
java.security.ProtectionDomain protectionDomain)
throws ClassFormatError;
1.1 protected final Class<?>
defineClass (String
name , byte[ ]
b , int
off , int
len )
throws ClassFormatError;
1.2 protected final Class<?>
defineClass (String
name , byte[ ]
b , int
off , int
len ,
java.security.ProtectionDomain
protectionDomain )
throws ClassFormatError;
1.2 protected Package
definePackage (String
name , String
specTitle , String
specVersion ,
String
specVendor , String
implTitle , String
implVersion , String
implVendor , java.net.URL
sealBase )
throws IllegalArgumentException;
1.2 protected Class<?>
findClass (String
name ) throws ClassNotFoundException;
1.2 protected String
findLibrary (String
libname ); constant
1.1 protected final Class<?>
findLoadedClass (String
name );
1.2 protected java.net.URL
findResource (String
name ); constant
1.2 protected java.util.Enumeration<java.net.URL>
findResources (String
name ) throws
java.io.IOException;
protected final Class<?>
findSystemClass (String
name ) throws ClassNotFoundException;
1.2 protected Package
getPackage (String
name );
1.2 protected Package[ ]
getPackages ( );
protected Class<?>
loadClass (String
name , boolean
resolve )
throws ClassNotFoundException; synchronized
protected final void
resolveClass (Class<?>
c );
1.1 protected final void
setSigners (Class<?>
c , Object[ ]
signers );
// Deprecated Protected Methods
# protected final Class<?>
defineClass (byte[ ]
b , int
off , int
len ) throws ClassFormatError;
}
Class.forName( ),
THRead.setContextClassLoader( ),
java.lang.instrument.ClassFileTransformer.transform(
),
java.lang.instrument.Instrumentation.getInitiatedClasses(
), java.lang.reflect.Proxy.{getProxyClass(
), newProxyInstance( )},
java.net.URLClassLoader.{newInstance( ),
URLClassLoader( )},
java.security.ProtectionDomain.ProtectionDomain(
),
java.security.SecureClassLoader.SecureClassLoader(
), java.util.ResourceBundle.getBundle( )
Class.getClassLoader( ),
SecurityManager.currentClassLoader( ),
Thread.getContextClassLoader( ),
java.security.ProtectionDomain.getClassLoader( )