Java Reference
In-Depth Information
(a)
(b)
(c)
(d)
(e)
(f)
F IGURE 3.8
Click Yes in (a), Yes in (b), No in (c), No in (d), and Yes in (e).
3.43
How do you display a confirmation dialog? What value is returned when invoking
JOptionPane.showConfirmDialog ?
Check
Point
3.19 Debugging
Debugging is the process of finding and fixing errors in a program.
Key
Point
As mentioned in Section 1.11,1, syntax errors are easy to find and easy to correct because
the compiler gives indications as to where the errors came from and why they are there.
Runtime errors are not difficult to find either, because the Java interpreter displays them on
the console when the program aborts. Finding logic errors, on the other hand, can be very
challenging.
Logic errors are called bugs . The process of finding and correcting errors is called
debugging . A common approach to debugging is to use a combination of methods to help pin-
point the part of the program where the bug is located. You can hand-trace the program (i.e.,
catch errors by reading the program), or you can insert print statements in order to show the
values of the variables or the execution flow of the program. These approaches might work for
debugging a short, simple program, but for a large, complex program, the most effective
approach is to use a debugger utility.
JDK includes a command-line debugger, jdb, which is invoked with a class name. jdb is
itself a Java program, running its own copy of Java interpreter. All the Java IDE tools, such as
Eclipse and NetBeans, include integrated debuggers. The debugger utilities let you follow the
execution of a program. They vary from one system to another, but they all support most of
the following helpful features.
bugs
debugging
hand-traces
Executing a single statement at a time: The debugger allows you to execute one
statement at a time so that you can see the effect of each statement.
Tracing into or stepping over a method: If a method is being executed, you can
ask the debugger to enter the method and execute one statement at a time in the
method, or you can ask it to step over the entire method. You should step over the
entire method if you know that the method works. For example, always step over
system-supplied methods, such as System.out.println .
 
 
Search WWH ::




Custom Search