Java Reference
In-Depth Information
course, you will need to find the path to Java on your computer, which may differ from
the one just shown. Also the specific version of the JDK may differ.) You will need to
consult the documentation for your operating system on how to set the path, because this
procedure differs between OSes.
The First Sample Program Line by Line
Although Example.java is quite short, it includes several key features that are common to
all Java programs. Let's closely examine each part of the program.
The program begins with the following lines:
This is a comment . Like most other programming languages, Java lets you enter a remark
into a program's source file. The contents of a comment are ignored by the compiler. In-
stead, a comment describes or explains the operation of the program to anyone who is read-
ing its source code. In this case, the comment describes the program and reminds you that
the source file should be called Example.java . Of course, in real applications, comments
generally explain how some part of the program works or what a specific feature does.
Java supports three styles of comments. The one shown at the top of the program is
called a multiline comment . This type of comment must begin with /* and end with */ .
Anything between these two comment symbols is ignored by the compiler. As the name
suggests, a multiline comment may be several lines long.
The next line of code in the program is shown here:
This line uses the keyword class to declare that a new class is being defined. As mentioned,
the class is Java's basic unit of encapsulation. Example is the name of the class. The class
definition begins with the opening curly brace ({) and ends with the closing curly brace
(}). The elements between the two braces are members of the class. For the moment, don't
worry too much about the details of a class except to note that in Java, all program activity
occurs within one. This is one reason why all Java programs are (at least a little bit) object-
oriented.
Search WWH ::




Custom Search