GeezerVison is showing docs.oracle.com — ClassLoader (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
compact1, compact2, compact3
java.lang
Class ClassLoader
-
-
Constructor Summary
Constructors
| Modifier |
Constructor |
Description |
protected |
ClassLoader() |
Creates a new class loader using the ClassLoader returned by
the method getSystemClassLoader() as the parent class loader.
|
protected |
ClassLoader(ClassLoader parent) |
Creates a new class loader using the specified parent class loader for
delegation.
|
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
| Modifier and Type |
Method |
Description |
void |
clearAssertionStatus() |
Sets the default assertion status for this class loader to
false and discards any package defaults or class assertion
status settings associated with the class loader.
|
protected Class<?> |
defineClass(byte[] b,
int off,
int len) |
|
protected Class<?> |
defineClass(String name,
byte[] b,
int off,
int len) |
Converts an array of bytes into an instance of class Class.
|
protected Class<?> |
defineClass(String name,
byte[] b,
int off,
int len,
ProtectionDomain protectionDomain) |
Converts an array of bytes into an instance of class Class,
with an optional ProtectionDomain.
|
protected Class<?> |
defineClass(String name,
ByteBuffer b,
ProtectionDomain protectionDomain) |
Converts a ByteBuffer
into an instance of class Class,
with an optional ProtectionDomain.
|
protected Package |
definePackage(String name,
String specTitle,
String specVersion,
String specVendor,
String implTitle,
String implVersion,
String implVendor,
URL sealBase) |
Defines a package by name in this ClassLoader.
|
protected Class<?> |
findClass(String name) |
|
protected String |
findLibrary(String libname) |
Returns the absolute path name of a native library.
|
protected Class<?> |
findLoadedClass(String name) |
Returns the class with the given binary name if this
loader has been recorded by the Java virtual machine as an initiating
loader of a class with that binary name.
|
protected URL |
findResource(String name) |
Finds the resource with the given name.
|
protected Enumeration<URL> |
findResources(String name) |
Returns an enumeration of URL objects
representing all the resources with the given name.
|
protected Class<?> |
findSystemClass(String name) |
Finds a class with the specified binary name,
loading it if necessary.
|
protected Object |
getClassLoadingLock(String className) |
Returns the lock object for class loading operations.
|
protected Package |
getPackage(String name) |
Returns a Package that has been defined by this class loader
or any of its ancestors.
|
protected Package[] |
getPackages() |
Returns all of the Packages defined by this class loader and
its ancestors.
|
ClassLoader |
getParent() |
Returns the parent class loader for delegation.
|
URL |
getResource(String name) |
Finds the resource with the given name.
|
InputStream |
getResourceAsStream(String name) |
Returns an input stream for reading the specified resource.
|
Enumeration<URL> |
getResources(String name) |
Finds all the resources with the given name.
|
static ClassLoader |
getSystemClassLoader() |
Returns the system class loader for delegation.
|
static URL |
getSystemResource(String name) |
Find a resource of the specified name from the search path used to load
classes.
|
static InputStream |
getSystemResourceAsStream(String name) |
Open for reading, a resource of the specified name from the search path
used to load classes.
|
static Enumeration<URL> |
getSystemResources(String name) |
Finds all resources of the specified name from the search path used to
load classes.
|
Class<?> |
loadClass(String name) |
|
protected Class<?> |
loadClass(String name,
boolean resolve) |
|
protected static boolean |
registerAsParallelCapable() |
Registers the caller as parallel capable.
|
protected void |
resolveClass(Class<?> c) |
Links the specified class.
|
void |
setClassAssertionStatus(String className,
boolean enabled) |
Sets the desired assertion status for the named top-level class in this
class loader and any nested classes contained therein.
|
void |
setDefaultAssertionStatus(boolean enabled) |
Sets the default assertion status for this class loader.
|
void |
setPackageAssertionStatus(String packageName,
boolean enabled) |
Sets the package default assertion status for the named package.
|
protected void |
setSigners(Class<?> c,
Object[] signers) |
Sets the signers of a class.
|
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
ClassLoader
protected ClassLoader()
Creates a new class loader using the ClassLoader returned by
the method getSystemClassLoader() as the parent class loader.
If there is a security manager, its checkCreateClassLoader method is invoked. This may result in
a security exception.
- Throws:
SecurityException - If a security manager exists and its
checkCreateClassLoader method doesn't allow creation
of a new class loader.
-
Method Detail
-
getClassLoadingLock
protected Object getClassLoadingLock(String className)
Returns the lock object for class loading operations.
For backward compatibility, the default implementation of this method
behaves as follows. If this ClassLoader object is registered as
parallel capable, the method returns a dedicated object associated
with the specified class name. Otherwise, the method returns this
ClassLoader object.
- Parameters:
className - The name of the to-be-loaded class
- Returns:
- the lock for class loading operations
- Throws:
NullPointerException - If registered as parallel capable and className is null
- Since:
- 1.7
- See Also:
loadClass(String, boolean)
-
defineClass
protected final Class<?> defineClass(String name,
byte[] b,
int off,
int len)
throws ClassFormatError
Converts an array of bytes into an instance of class Class.
Before the Class can be used it must be resolved.
This method assigns a default ProtectionDomain to the newly defined class. The
ProtectionDomain is effectively granted the same set of
permissions returned when Policy.getPolicy().getPermissions(new CodeSource(null, null))
is invoked. The default domain is created on the first invocation of
defineClass,
and re-used on subsequent invocations.
To assign a specific ProtectionDomain to the class, use
the defineClass method that takes a
ProtectionDomain as one of its arguments.
- Parameters:
name - The expected binary name of the class, or
null if not known
b - The bytes that make up the class data. The bytes in positions
off through off+len-1 should have the format
of a valid class file as defined by
The Java™ Virtual Machine Specification.
off - The start offset in b of the class data
len - The length of the class data
- Returns:
- The Class object that was created from the specified
class data.
- Throws:
ClassFormatError - If the data did not contain a valid class
IndexOutOfBoundsException - If either off or len is negative, or if
off+len is greater than b.length.
SecurityException - If an attempt is made to add this class to a package that
contains classes that were signed by a different set of
certificates than this class (which is unsigned), or if
name begins with "java.".
- Since:
- 1.1
- See Also:
loadClass(String, boolean),
resolveClass(Class),
CodeSource,
SecureClassLoader
-
defineClass
protected final Class<?> defineClass(String name,
byte[] b,
int off,
int len,
ProtectionDomain protectionDomain)
throws ClassFormatError
Converts an array of bytes into an instance of class Class,
with an optional ProtectionDomain. If the domain is
null, then a default domain will be assigned to the class as
specified in the documentation for defineClass(String, byte[],
int, int). Before the class can be used it must be resolved.
The first class defined in a package determines the exact set of
certificates that all subsequent classes defined in that package must
contain. The set of certificates for a class is obtained from the
CodeSource within the
ProtectionDomain of the class. Any classes added to that
package must contain the same set of certificates or a
SecurityException will be thrown. Note that if
name is null, this check is not performed.
You should always pass in the binary name of the
class you are defining as well as the bytes. This ensures that the
class you are defining is indeed the class you think it is.
The specified name cannot begin with "java.", since
all classes in the "java.* packages can only be defined by the
bootstrap class loader. If name is not null, it
must be equal to the binary name of the class
specified by the byte array "b", otherwise a NoClassDefFoundError will be thrown.
- Parameters:
name - The expected binary name of the class, or
null if not known
b - The bytes that make up the class data. The bytes in positions
off through off+len-1 should have the format
of a valid class file as defined by
The Java™ Virtual Machine Specification.
off - The start offset in b of the class data
len - The length of the class data
protectionDomain - The ProtectionDomain of the class
- Returns:
- The Class object created from the data,
and optional ProtectionDomain.
- Throws:
ClassFormatError - If the data did not contain a valid class
NoClassDefFoundError - If name is not equal to the binary
name of the class specified by b
IndexOutOfBoundsException - If either off or len is negative, or if
off+len is greater than b.length.
SecurityException - If an attempt is made to add this class to a package that
contains classes that were signed by a different set of
certificates than this class, or if name begins with
"java.".
-
resolveClass
protected final void resolveClass(Class<?> c)
Links the specified class. This (misleadingly named) method may be
used by a class loader to link a class. If the class c has
already been linked, then this method simply returns. Otherwise, the
class is linked as described in the "Execution" chapter of
The Java™ Language Specification.
- Parameters:
c - The class to link
- Throws:
NullPointerException - If c is null.
- See Also:
defineClass(String, byte[], int, int)
-
setSigners
protected final void setSigners(Class<?> c,
Object[] signers)
Sets the signers of a class. This should be invoked after defining a
class.
- Parameters:
c - The Class object
signers - The signers for the class
- Since:
- 1.1
-
definePackage
protected Package definePackage(String name,
String specTitle,
String specVersion,
String specVendor,
String implTitle,
String implVersion,
String implVendor,
URL sealBase)
throws IllegalArgumentException
Defines a package by name in this ClassLoader. This allows
class loaders to define the packages for their classes. Packages must
be created before the class is defined, and package names must be
unique within a class loader and cannot be redefined or changed once
created.
- Parameters:
name - The package name
specTitle - The specification title
specVersion - The specification version
specVendor - The specification vendor
implTitle - The implementation title
implVersion - The implementation version
implVendor - The implementation vendor
sealBase - If not null, then this package is sealed with
respect to the given code source URL object. Otherwise, the package is not sealed.
- Returns:
- The newly defined Package object
- Throws:
IllegalArgumentException - If package name duplicates an existing package either in this
class loader or one of its ancestors
- Since:
- 1.2
-
findLibrary
protected String findLibrary(String libname)
Returns the absolute path name of a native library. The VM invokes this
method to locate the native libraries that belong to classes loaded with
this class loader. If this method returns null, the VM
searches the library along the path specified as the
"java.library.path" property.
- Parameters:
libname - The library name
- Returns:
- The absolute path of the native library
- Since:
- 1.2
- See Also:
System.loadLibrary(String),
System.mapLibraryName(String)
-
clearAssertionStatus
public void clearAssertionStatus()
Sets the default assertion status for this class loader to
false and discards any package defaults or class assertion
status settings associated with the class loader. This method is
provided so that class loaders can be made to ignore any command line or
persistent assertion status settings and "start with a clean slate."
- Since:
- 1.4
Java™ Platform Standard Ed. 8
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|