Programming and Problem Solving with Java

(やまだぃちぅ) #1

(^194) | Selection and Encapsulation


Tests Performed Automatically During Compilation and Execution


Once a design is coded and test data have been prepared, the application is ready for
compiling. The compiler has two responsibilities: to report any errors and, if there are no
errors, to translate the source code into object code or Bytecode.
Errors can be either syntactic or semantic. The compiler finds syntactic errors. For ex-
ample, the compiler warns you when reserved words are misspelled, identifiers are un-
declared, semicolons are missing, and operand types are mismatched. But it won’t find
all of your typing errors. If you type >instead of <, you won’t receive an error message; in-
stead, you will get erroneous results when you test the code. It’s your responsibility to de-
sign a test plan and carefully check the code to detect errors of this type.
Semantic errors(also calledlogic errors) are mistakes that give you the wrong answer.
They are more difficult to locate than syntactic errors and usually surface when code is
executing. Java detects only the most obvious semantic errors—those that result in an in-
valid operation (dividing by zero, for example). Although typing errors sometimes cause
semantic errors, they are more often a product of a faulty algorithm design. By walking

Figure 4.8 When You Test a Program without a Plan, You Never Know What You Might Be Missing
Free download pdf