Java Reference
In-Depth Information
Chapter 12. Execution
This chapter specifies activities that occur during execution of a program. It is organized
around the life cycle of the Java Virtual Machine and of the classes, interfaces, and objects
that form a program.
The Java Virtual Machine starts up by loading a specified class and then invoking the meth-
od main in this specified class. Section § 12.1 outlines the loading, linking, and initialization
steps involved in executing main , as an introduction to the concepts in this chapter. Further
sections specify the details of loading (§ 12.2 ), linking (§ 12.3 ), and initialization (§ 12.4 ).
The chapter continues with a specification of the procedures for creation of new class in-
stances (§ 12.5 ) ; and finalization of class instances (§ 12.6 ). It concludes by describing the
unloading of classes (§ 12.7 ) and the procedure followed when a program exits (§ 12.8 ).
12.1. Java Virtual Machine Startup
The Java Virtual Machine starts execution by invoking the method main of some specified
class, passing it a single argument, which is an array of strings. In the examples in this spe-
cification, this first class is typically called Test .
The precise semantics of Java Virtual Machine startup are given in Chapter 5 of The Java
Virtual Machine Specification, Java SE 7 Edition . Here we present an overview of the pro-
cess from the viewpoint of the Java programming language.
The manner in which the initial class is specified to the Java Virtual Machine is beyond the
scope of this specification, but it is typical, in host environments that use command lines,
for the fully-qualified name of the class to be specified as a command-line argument and for
following command-line arguments to be used as strings to be provided as the argument to
the method main .
For example, in a UNIX implementation, the command line:
java Test reboot Bob Dot Enzo
will typically start a Java Virtual Machine by invoking method main of class Test (a class
in an unnamed package), passing it an array containing the four strings “ reboot ”, “ Bob ”,
Dot ”, and “ Enzo ”.
We now outline the steps the Java Virtual Machine may take to execute Test , as an example of
the loading, linking, and initialization processes that are described further in later sections.
Search WWH ::




Custom Search