Java Reference
In-Depth Information
12.1.1. Load the Class
Test
The initial attempt to execute the method
main
of class
Test
discovers that the class
Test
is
not loaded - that is, that the Java Virtual Machine does not currently contain a binary rep-
resentation for this class. The Java Virtual Machine then uses a class loader to attempt to
find such a binary representation. If this process fails, then an error is thrown. This loading
12.1.2. Link
Test
: Verify, Prepare, (Optionally) Resolve
After
Test
is loaded, it must be initialized before
main
can be invoked. And
Test
, like all
(class or interface) types, must be linked before it is initialized. Linking involves verifica-
Verification checks that the loaded representation of
Test
is well-formed, with a proper sym-
bol table. Verification also checks that the code that implements
Test
obeys the semantic re-
quirements of the Java programming language and the Java Virtual Machine. If a problem
is detected during verification, then an error is thrown. Verification is described further in
Preparation involves allocation of static storage and any data structures that are used intern-
ally by the implementation of the Java Virtual Machine, such as method tables. Preparation
Resolution is the process of checking symbolic references from
Test
to other classes and
interfaces, by loading the other classes and interfaces that are mentioned and checking that
the references are correct.
The resolution step is optional at the time of initial linkage. An implementation may resolve
symbolic references from a class or interface that is being linked very early, even to the
point of resolving all symbolic references from the classes and interfaces that are further
referenced, recursively. (This resolution may result in errors from these further loading and
linking steps.) This implementation choice represents one extreme and is similar to the
kind of “static” linkage that has been done for many years in simple implementations of
the C language. (In these implementations, a compiled program is typically represented as
an “
a.out
” file that contains a fully-linked version of the program, including completely re-
solved links to library routines used by the program. Copies of these library routines are
included in the “
a.out
” file.)
An implementation may instead choose to resolve a symbolic reference only when it is act-
ively used; consistent use of this strategy for all symbolic references would represent the
“laziest” form of resolution. In this case, if
Test
had several symbolic references to another