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:
PowerOfTwo
class (the file should
be called PowerOfTwo.java).
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.