Java Reference
In-Depth Information
They should not belabor the obvious but should provide appropriate insight into
the intent of the code. The following examples are
not good comments:
System.out.println ("hello"); // prints hello
System.out.println ("test"); // change this later
The first comment paraphrases the obvious purpose of the line and
does not add any value to the statement. It is better to have no com-
ment than a useless one. The second comment is ambiguous. What
should be changed later? When is later? Why should it be changed?
KEY CONCEPT
Inline documentation should provide
insight into your code. It should not
be ambiguous or belabor the obvious.
Identifiers and Reserved Words
The various words used when writing programs are called
identifiers. The identi-
fiers in the Lincoln program are class , Lincoln , public , static , void , main ,
String , args , System , out , and println . These fall into three categories:
words that we make up when writing a program ( Lincoln and args )
words that another programmer chose ( String , System , out , println , and
main )
words that are reserved for special purposes in the language ( class ,
public , static , and void )
While writing the program, we simply chose to name the class Lincoln , but
we could have used one of many other possibilities. For example, we could have
called it Quote , or Abe , or GoodOne . The identifier args (which is short for argu-
ments) is often used in the way we use it in Lincoln , but we could have used just
about any other identifier in its place.
The identifiers String , System , out , and println were chosen by other pro-
grammers. These words are not part of the Java language. They are part of the
Java standard library of predefined code, a set of classes and methods that some-
one has already written for us. The authors of that code chose the identifiers in
that code—we're just making use of them.
Reserved words are identifiers that have a special meaning in a programming
language and can only be used in predefined ways. A reserved word cannot be
used for any other purpose, such as naming a class or method. In the Lincoln pro-
gram, the reserved words used are class , public , static , and void. Throughout
the topic, we show Java reserved words in blue type. Figure 1.18 lists all of the
Java reserved words in alphabetical order. The words marked with an asterisk
have been reserved, but currently have no meaning in Java.
An identifier that we make up for use in a program can be composed of
any combination of letters, digits, the underscore character ( _ ), and the dol-
lar sign ( $ ), but it cannot begin with a digit. Identifiers may be of any length.
 
Search WWH ::




Custom Search