public static void main(String[] args )
The Java compiler would accept the line. But it looks sloppy to human eyes.
println()
class Hello
{
public static void main ( String[] args )
{
System.out.println("Hello World!");
}
}
There are rules about where spaces may be used, and optional style rules about how to make a program look nice. Rather than look at a list of rules, look at some Java programs and pick up the rules by example.
The main method of this program consists of a single statement:
System.out.println("Hello World!");
This statement writes the characters inside the quotation marks to the monitor of the computer system. (The quotation marks are not written.)
A statement in a programming language is a command for the computer to do something. It is like a sentence of the language. A statement in Java is followed by a semicolon.
Methods are built out of statements.
The statements in a method are placed between
braces { and } as in
this example.
The part "Hello World!" is called a string.
A string is a sequence of characters.
This program writes a string to the monitor and then stops.
(Review: ) Say that the file Hello.java contains the example program.
The file is contained in the subdirectory C:\Temp on the hard disk.
In order to run it, what two things must be done?