Java Reference
In-Depth Information
the first program
1.2
Let us begin by examining the simple Java program shown in Figure 1.1. This
program prints a short phrase to the terminal. Note the line numbers shown on the
left of the code are not part of the program . They are supplied for easy reference.
Place the program in the source file FirstProgram.java and then compile
and run it. Note that the name of the source file must match the name of the
class (shown on line 4), including case conventions. If you are using the JDK,
the commands are 1
javac FirstProgram.java
java FirstProgram
1.2.1 comments
Java has three forms of comments. The first form, which is inherited from C,
begins with the token /* and ends with */ . Here is an example:
/* This is a
two-line comment */
Comments do not nest.
The second form, which is inherited from C++, begins with the token // .
There is no ending token. Rather, the comment extends to the end of the line.
This is shown on lines 1 and 2 in Figure 1.1.
The third form begins with /** instead of /* . This form can be used to
provide information to the javadoc utility, which will generate documentation
from comments. This form is discussed in Section 3.3.
Comments make
code easier for
humans to read.
Java has three
forms of comments.
1 // First program
2 // MW, 5/1/10
3
4 public class FirstProgram
5 {
6 public static void main( String [ ] args )
7 {
8 System.out.println( "Is there anybody out there?" );
9 }
10 }
figure 1.1
A simple first program
1. If you are using Sun's JDK, javac and java are used directly. Otherwise, in a typical interac-
tive development environment (IDE), such as Netbeans or Eclipse these commands are
executed behind the scenes on your behalf.
 
 
 
Search WWH ::




Custom Search