Java Reference
In-Depth Information
The only term you can change in this signature of main() is the name of the
parameter args, which can be any valid identifier name. The array of strings
(String []) will contain the command-line arguments, if any, when the program
is executed from the command prompt.
Within main() is a single statement:
System.out.println(“Hello, World”);
This statement is what causes “Hello, World” to appear at the command
prompt—or in this case, the standard output. System.out represents the stan-
dard output of the device where this program is running, and the println()
(short for print line) method displays the given string along with a line feed.
Notice the semicolon at the end of the System.out.println() statement. The
Java compiler ignores all whitespace and indenting, so it is necessary to use a
semicolon to denote the end of all statements in Java.
Step 2: Compile the Program
The javac tool compiles Java classes into bytecode. Figure 1.7 shows how to
compile the HelloWorld.java class from Figure 1.6. Notice the use of the cd
command to change directories to the one where the HelloWorld.java file is
located.
If the compiler is successful, no message will be displayed and the com-
mand prompt will come back. Notice in Figure 1.7 the use of the dir command
to display the contents of the current directory. You should see a new file: Hel-
loWorld.class. This is the bytecode file generated from the compiler.
All bytecode appears in .class files. The extension is appropriate because
within that .class file is the bytecode describing a single class. In this case, Hel-
loWorld.class contains the bytecode of the HelloWorld class, which is a class
containing one method, main().
Figure 1.7
Use the javac tool to compile HelloWorld.java.
Search WWH ::




Custom Search