Java Reference
In-Depth Information
To run the program you type the command
java HelloWorld
This executes the
main
method of
HelloWorld
. When you run the program,
it displays
Hello, world
Now you have a small program that does something, but what does it
mean?
The program declares a class called
HelloWorld
with a single member: a
method called
main
. Class members appear between curly braces
{
and
}
following the class name.
The
main
method is a special method: the
main
method of a class, if de-
clared exactly as shown, is executed when you run the class as an ap-
plication. When run, a
main
method can create objects, evaluate expres-
sions, invoke other methods, and do anything else needed to define an
application's behavior.
The
main
method is declared
public
so that anyone can invoke it (in this
case the Java virtual machine)and
static
, meaning that the method be-
longs to the class and is not associated with a particular instance of the
class.
Preceding the method name is the return type of the method. The
main
method is declared
void
because it doesn't return a value and so has no
return type.
Following the method name is the
parameter
list for the methoda se-
quence of zero or more pairs of types and names, separated by commas
and enclosed in parentheses
(
and
)
. The
main
method's only paramet-