Java Reference
In-Depth Information
the first line of the error message itself, and TextPad will open the coding
window automatically, placing the insertion point at the beginning of the line in
question. Once the errors are fixed, save the file and then compile the program
again. If Java still displays error messages after you have corrected all syntax or
semantic errors, consult your instructor.
Logic and Run-Time Errors
A logic error occurs when a program does not behave as intended due to
poor design or incorrect implementation of the design. A run-time error , also
called an exception , is an error that occurs when unexpected conditions arise as
you run or execute the program. Even programs that compile successfully may
display logic or run-time errors if the programmer has not thought through the
logical processes and structures of the program. Your goal should be to have
error-free programs, and by implementing the development cycle correctly,
you will achieve that goal.
Occasionally, a logic error will surface during execution of the program due
to an action the user performs — an action for which the programmer did not
plan. For example, if a user inputs numbers outside of valid ranges or enters the
wrong types of data, the program may stop executing if the code cannot handle
the input. In later chapters, you will learn how to write code to handle data entry
errors based on validity, range, and reasonableness. In this chapter, the user
inputs no data into the application, so these types of logic errors should not
occur.
Other logic or run-time errors may occur as you run a program. For exam-
ple, if a programmer typed the wrong data or used an incorrect operator in
code, the program would compile and run correctly, but the wrong output
would display. No run-time error message would occur. These types of errors
can be difficult to identify.
A run-time error message also will display if you are executing the program
from the command prompt window and misspell the command, misspell the
name of the bytecode file, or add an extension by mistake.
Running the Application
After a Java program is compiled into bytecode, and syntax and semantic errors
are fixed, the program must be run or executed to test for logic and run-time
errors. Programmers run the program to display output, receive input from the
user if necessary, and interpret the commands to produce the desired result.
Running the Application
TextPad includes a Run Java Application command on the Tools menu.
The Run Java Application command executes the compiled bytecode of the file
selected in the Selector window. TextPad automatically looks for the class file
with the same name and then executes it. If you are running the application
from the command prompt, you type java followed by the name of the class
file, Welcome (no extension). Perform the steps on the next page to run the
Welcome to My Day application.
Search WWH ::




Custom Search