Every complete Java program must contain a root class where execution can begin. A root class must contain a main method defined with the header
public static void main(String[] args)
To execute a Java program, a user must identify the name of the root class for the program. In most Java computing environments, the command required to execute the Java program with root class C is simply
java CNote that a class may contain a main method even if it is not intended to be the root class of an actual program. Of course, evaluating the DrJava expression
Motto.main(null);is equivalent to executing this conssoled. For the sake of programming convenience, the DrJava Interactions pane accepts the command line syntax as well as the explicit invocation of the main method shown above.
When execution begins in the main method of a root class, no instances of the root class exist. In fact, most Java programs never instantiate the root class because it serves as a framework for organizing program execution rather than a definition of a new form of data. Java classes really serve two distinct purposes: defining data objects and organizing static methods and variables.
The args parameter of the main method in the root class is used to pass command line options to the Java program. We will not use this feature in this monograph.