2.3 Application Entry, Correction, and Execution | 77
Compiling and Running an Application
Once your application is stored in a file, you compile it by issuing a command to run the Java
compiler. The compiler translates the application and then stores the Bytecode version into
a new file. Sometimes, the compiler may display a
window with messages indicating errors in the ap-
plication. Some systems let you click on an error
message to automatically position the cursor in
the editor window at the point where the error was
detected.
If the compiler finds errors in your application
(syntax errors), you must determine their cause, re-
turn to the editor and fix them, and then run the
compiler again. Once your application compiles
without errors, you can run (execute) it.
Some systems automatically run an application
when it compiles successfully. On other systems,
you must issue a separate command to run the ap-
plication. Whatever series of commands your sys-
tem uses, the result is the same: Your application is
loaded into memory and executed by the JVM.
Even though an application runs, it still may
have errors in its design. After all, the computer
does exactly what you tell it to do, even if that’s
not what you intended. If your application doesn’t
do what it should (a logic error), you must revise the
algorithm, and then go to the editor and fix the
code. Finally, you compile and run the code again.
This debuggingprocess is repeated until the application works as planned (see Figure 2.6).
Finishing Up
On a workstation, once you finish working on your code, you have tolog offby typing the
appropriate command. This practice frees up the workstation so that someone else can
use it. It also prevents someone from walking up after you leave and tampering with
your files.
On a personal computer, when you’re done working, you save your files and quit the ed-
itor. Turning off the power wipes out what’s in the computer’s short-term memory, but your
files remain stored safely on disk. It is a wise precaution to periodically make a copy of your
code files on a removable diskette. When a disk in a computer suffers a hardware failure, it
is impossible to retrieve your files. Having a backup copy on a diskette enables you to restore
your files to the disk once it is repaired.
Be sure to read the manual for your particular system and editor before you enter your
first application. Don’t panic if you have trouble at first—almost everyone does. The process
Enter program
Compile program
Compiler errors?
Run program
Execution errors?
Success!
Figure out errors,
get back into editor,
and fix errors in
program.
Go back to algorithm
and fix design. Get back
into editor and fix errors
in program.
Yes
Yes
No
Figure 2.6 The Debugging Process