Java Reference
In-Depth Information
We see that this object has two instance variables (or fields), server and user , and we can see
the current values. The user variable stores the string "Juan" , and the server variable stores
a reference to another object. The object reference is what we have drawn as an arrow in the
object diagrams.
Note that there is no local variable yet. This is because execution stops before the line with the
breakpoint is executed. Because the line with the breakpoint contains the declaration of the only
local variable and that line has not yet been executed, no local variable exists at the moment.
The debugger not only allows us to interrupt the execution of the program and inspect the vari-
ables, it also lets us step forward slowly.
Single stepping
When stopped at a breakpoint, clicking the Step button executes a single line of code and
then stops again.
Exercise 3.37 Step one line forward in the execution of the printNextMailItem method
by clicking the Step button.
The result of executing the first line of the printNextMailItem method is shown in
Figure 3.7. We can see that execution has moved on by one line (a small black arrow next to
the line of source code indicates the current position), and the local variable list in the debug-
ger window indicates that a local variable item has been created and an object assigned to it.
Figure 3.7
Stopped again after
a single step
Exercise 3.38 Predict which line will be marked as the next line to execute after the next
step. Then execute another single step and check your prediction. Were you right or wrong?
Explain what happened and why.
Search WWH ::

Custom Search