Java Reference
In-Depth Information
The compiler checks to make sure you are using the correct syn-
tax. If you have any statements that do not conform to the syntactic
rules of the language, the compiler will produce a syntax error. The
compiler also tries to find other problems, such as the use of incom-
patible types of data. The syntax might be technically correct, but
you may be attempting to do something that the language doesn't semantically
allow. Any error identified by the compiler is called a
KEY CONCEPT
A Java program must be syntactically
correct or the compiler will not pro-
duce bytecode.
compile-time error. If a
compile-time error occurs, an executable version of the program is not created.
The second kind of problem occurs during program execution. It is called a
run-time error and causes the program to terminate abnormally. For example, if
we attempt to divide by zero, the program will “crash” and halt execution at that
point. Because the requested operation is undefined, the system simply abandons
its attempt to continue processing your program. The best programs are robust ;
that is, they avoid as many run-time errors as possible. For example, the program
code could guard against the possibility of dividing by zero and handle the situa-
tion appropriately if it arises. In Java, many run-time problems are called excep-
tions that can be caught and dealt with accordingly.
The third kind of software problem is a logical error. In this case, the software
compiles and executes without complaint, but it produces incorrect results. For
example, a logical error occurs when a value is calculated incorrectly or when a
graphical button does not appear in the correct place. A programmer must test the
program thoroughly, comparing the expected results to those that actually occur.
When defects are found, they must be traced back to the source of the problem in
the code and corrected. The process of finding and correcting defects in a program
is called debugging. Logical errors can manifest themselves in many ways, and the
actual root cause might be difficult to discover.
VideoNote
Examples of various
error types.
SELF-REVIEW QUESTIONS (see answers in Appendix N)
SR 1.27 We all know that computers are used to perform complex jobs. In this
section, you learned that a computer's instructions can do only simple
tasks. Explain this apparent contradiction.
SR 1.28 What is the relationship between a high-level language and a machine
language?
SR 1.29 What is Java bytecode?
SR 1.30 Select the word from the following list that best matches each of the
following phrases:
assembly, compiler, high-level, IDE, interpreter, Java, low-level, machine
a. A program written in this type of language can run directly on a
computer.
 
Search WWH ::




Custom Search