Java Reference
In-Depth Information
Exercise 16.11 : Expand on Game and Player to implement a simple
game, such as tic-tac-toe. Score some Player implementations over sev-
eral runs each.
16.13.2. Preparing a Class for Use
The class loader assists in only the first stage of making a class avail-
able. There are three steps in all:
1. Loading Getting the bytecodes that implement the class and cre-
ating a Class object.
2. Linking Verifying that the class's bytecodes conform to the lan-
guage rules, preparing the virtual machine by allocating space for
static fields, and (optionally) resolving all references in the class
by, if necessary, loading the classes referred to.
3. Initialization Initializing the superclass (if necessary, including
loading and linking it), then executing all the static initializers and
static initialization blocks of the class.
The Class object returned by defineClass only represents a loaded classit
has not yet been linked. You can explicitly link by invoking the (mis-
named) resolveClass method:
protected final void resolveClass(Class<?> c)
Links the specified class if it has not already been linked.
The loadClass method we described does not resolve the class that is
loaded. A protected, overloaded form of loadClass takes an additional
boolean flag indicating whether or not to resolve the class before return-
ing. The virtual machine will ensure that a class is resolved (linked) be-
fore it is initialized.
A class must be initialized immediately before the first occurrence of: an
instance of the class being created; a static method of the class being
 
Search WWH ::




Custom Search