Java Reference
In-Depth Information
Every Java application contains a class with a
main
method. When the application
starts, the instructions in the
main
method are executed.
The parameter
String[] args
is a required part of the
main
method. (It contains
command line arguments, which we will not discuss until
Chapter 11
.) The keyword
static
indicates that the
main
method does not operate on an object. (As you will
see in
Chapter 2
, most methods in Java do operate on objects, and
static
methods
are not common in large Java programs. Nevertheless,
main
must always be
static
,
because it starts running before the program can create objects.)
Each class contains definitions of methods. Each method contains a sequence of
instructions.
19
20
At this time, simply consider
public class
ClassName
{
public static void main(String[] args)
{
. . .
}
}
as yet another part of the Ȓplumbingȓ. Our first program has all instructions inside the
main
method of a class.
The first line inside the
main
method is a comment
// Display a greeting in the console window
This comment is purely for the benefit of the human reader, to explain in more detail
what the next statement does. Any text enclosed between
//
and the end of the line is
completely ignored by the compiler. Comments are used to explain the program to
other programmers or to yourself.
Use comments to help human readers understand your program.