Programming and Problem Solving with Java

(やまだぃちぅ) #1
2.5 Testing and Debugging | 87

10.Make sure your statements end with semicolons (except blocks, which do not have a semicolon
after the right brace).
11.On most Java systems, the file name that holds the program must be the same as the name of
the class, but with the extension .java. For example, the program NameDriveris stored in a file
called NameDriver.java. Using another name will produce an error message from the compiler.
12.Be careful when using the /* */pair to delimit comments. If you forget the */, then everything
that follows until the end of the next /* */comment (or the end of your program) will be treated
as a comment. Also, remember to avoid starting comments of this form with two asterisks (/**)
because comments of that form are used by the javadocprogram.
13.Confirm that every open brace ({) in your program is matched by a close brace (}) in the appropriate
place. Braces determine the beginning and end of blocks in Java, and their placement affects the
structure of the program. Similarly, it is always wise to confirm that parentheses are used in
matched pairs in your program.
14.Instantiate instances of every class variable by using new.
15.When instantiating an object in an argument list, include the newoperator before the class name.
16.Objects to which methods are being applied must have the method name appended to the object
name with a dot in between.
17.Be clear about which methods are class methods and which are instance methods. When you
call a class method, its name is appended to the name of the class. When you call an instance
method, its name is appended to an object identifier.
18.Make sure that the application class and mainare public, and that any user classes are not public.
19.Include the throwsclause in the heading of any method that uses readLine.

Summary


The syntax (grammar) of the Java language is defined by a metalanguage. In this book,
we use a form of metalanguage called syntax templates. We describe the semantics
(meaning) of Java statements in English.
Identifiers are used in Java to name things. Some identifiers, called reserved words,
have predefined meanings in the language; others are created by the programmer.
The identifiers you invent are restricted to those notreserved by the Java language.
(Reserved words are listed in Appendix A.)
Identifiers are associated with memory locations through declarations. A
declaration may give a name to a location whose value does not change (a constant)

Free download pdf