Sponsored Link •
The loading process consists of three basic activities. To load a type, the Java virtual machine must:
java.lang.Classthat represents the type
The Java virtual machine specification does not say how the binary data for a type must be produced. Some potential ways to produce binary data for a type are:
java.lang.Class. The virtual machine must parse the binary data into implementation-dependent internal data structures. (See Chapter 5, "The Java Virtual Machine," for a discussion of potential internal data structures for storing class data.) The
Classinstance, the end product of the loading step, serves as an interface between the program and the internal data structures. To access information about a type that is stored in the internal data structures, the program invokes methods on the
Classinstance for that type. Together, the processes of parsing the binary data for a type into internal data structures in the method area and instantiating a
Classobject on heap are called creating the type.
As described in previous chapters, types are loaded either through the bootstrap class loader or through
user-defined class loaders. The bootstrap class loader, a part of the virtual machine implementation, loads
types (including the classes and interfaces of the Java API) in an implementation-dependent way. User-
defined class loaders, instances of subclasses of
classes in custom ways. The inner workings of user-defined class loaders are described in more detail later in
Chapter 8, "The Linking Model."
Class loaders (bootstrap or user-defined) need not wait until a type's first active use before they load the
type. Class loaders are allowed to cache binary representations of types, load types early in anticipation of
eventual use, or load types together in related groups. If a class loader encounters a problem during early
loading, however, it must report that problem (by throwing a subclass of
LinkageError) only upon the type's first active use. In other words, if a class loader
encounters a missing or malformed class file during early loading, it must wait to report that error until the
class's first active use by the program. If the class is never actively used by the program, the class loader will
never report the error.