Java Reference
In-Depth Information
17
1.6 Compiling a Simple Program
You are now ready to write and run your first Java program. The traditional choice for
the very first program in a new programming language is a program that displays a
simple greeting: ȒHello, World!ȓ. Let us follow that tradition. Here is the ȒHello,
World!ȓ program in Java.
ch01/hello/HelloPrinter.java
1
public class
HelloPrinter
2{
3
public static void
main(String[] args)
4 {
5//
Display a greeting in the console window
6
7 System.out.println (
ÐHello, World!Ñ
);
8 }
9}
Output
Hello, World!
We will examine this program in a minute. For now, you should make a new program
file and call it
HelloPrinter.java
. Enter the program instructions and compile
and run the program, following the procedure that is appropriate for your compiler.
Java is case sensitive. You must enter upper- and lowercase letters exactly as they
appear in the program listing. You cannot type
MAIN
or
PrintLn
. If you are not
careful, you will run into problemsȌsee
Common Error 1.2
.
Java is case sensitive. You must be careful about distinguishing between upper- and
lowercase letters.
On the other hand, Java has free-form layout. You can use any number of spaces and
line breaks to separate words. You can cram as many words as possible into each line,
public class HelloPrinter{public static void
main(String[]