Gild Debugger (cont'd)

Step 1: Setting Break Points

In order to see how the program is running in the background, we will need to have some way of interacting with the source code as the program is running. If we are going to do that, we will need to have some method of stopping the program. This is what breakpoints are for. Placing a breakpoint on a line will cause your program to pause execution just before that line.

By looking at the output of our program, we can see that the System.out.println() statement within the while loop is not printing what we expect. So, the while loop is a good place to start our debugging. We will place our breakpoint on line 22: the one with the System.out.println() statement:

  1. Right-click on line 22 in the vertical ruler of the Gild Editor that is displaying the code for our PowerOfTwo class (the file should be called PowerOfTwo.java).
  2. In the pop-up menu, select "Add/Remove Breakpoint" or "Add Breakpoint".

You will now see a small circle image beside the line at which the breakpoint occurs. You will also see the breakpoint within the Breakpoints View on the right-hand side of your screen.

You are now ready to start the debugger to debug our code.


Previous | Index | Next