Java 7 for Absolute Beginners

(nextflipdebug5) #1

CHAPTER 11 ■ DEBUGGING WITH ECLIPSE


g.drawLine(burstX, burstY, endX, endY);
}
}
currentStep++;
}

The parts I added are in bold. Simple little oversights such as this one are a common source of bugs.
So, remember to fully understand what your code is doing and to proofread very carefully. And you'll
still miss things, which is why you should get to know at least one good debugger.
Figure 11-11 shows the values yielded by the correct code.

Figure 11-11. Correct values in the debugger

As you can see, the values for endX and endY are closer to the values I expected, which brings us to
one more thing that you need to do when writing software: figure out what values to expect. If you don't
know what values should appear in the debugger, you can't be sure your code is doing the right (or
wrong) thing.

Summary


We covered a lot of ground in this chapter. You learned:


  • The general flow of debugging.

  • How to debug without a debugger (and why it’s better to have one).

  • How to set a line breakpoint.

  • That other kinds of breakpoints are available to expand with your debugging
    needs.

  • How to step over code and how to step into code.

  • How to examine the values of the variables as they are affected by the code.

Free download pdf