Java Reference
In-Depth Information
A disadvantage is that debuggers typically do not keep a permanent record of state changes, so
it is harder to go back and check the state as it was a few statements earlier.
A debugger typically also gives you information about the call sequence (or stack ) at each point
in time. The call sequence shows the name of the method containing the current statement, the
name of the method that the current method was called from, and the name of the method that
that method was called from, and so on. Thus, the call sequence contains a record of all cur-
rently active, unfinished methods—similar to what we have done manually during our walk-
through by writing marks next to method-call statements.
In BlueJ, the call sequence is displayed on the left-hand side of the debugger window (Figure 7.9).
Every method name in that sequence can be selected to inspect the current values of that method's
local variables.
Figure 7.9
The BlueJ debugger
window, with
execution stopped at
a breakpoint
Exercise 7.34 Using the calculator-engine project, set a breakpoint in the first line of the
testPlus method in the CalcEngineTester class. Execute this method. When the
debugger appears, walk through the code step by step. Experiment with both the Step and
Step Into buttons.
Exercise 7.35 Challenge exercise In practice, you will probably find that Hacker
T.  Largebrain's attempt to program the CalcEngine class is too full of errors to be worth
trying to fix. Instead, write your own version of the class from scratch. The calculator-gui
project contains classes that provide the GUI shown in Figure 7.6. You can use this project as
the basis for your own implementation of the CalcEngine class. Be sure to document your
class thoroughly and to create a thorough set of tests for your implementation so that your
experience with Hacker's code will not have to be repeated by your successor! Make sure to
use dedicated unit test classes for your testing, instead of writing tests into standard classes;
as you have seen, this makes asserting the correct results much easier.
 
Search WWH ::




Custom Search