Java Reference
In-Depth Information
Recall that when running the program at this stage, the result was much lower than expected. You
would like to find the bug and you've narrowed it down to two possibilities. The actual recalcu-
late method might be programmed wrong or the for loop might not be using the method correctly.
Therefore, you can place a breakpoint in each place to see what's happening there.
To place a breakpoint, move your cursor to the left of the line number you're interested in. You can
either double‐click there or right‐click and select Toggle Breakpoint. You should see a small dot
appear next to the line number, as shown in Figure 6-10.
figure 6-10  
Once your breakpoints are set, all you need to do is open the debug perspective. There are several
ways to do this:
1. Click the Bug icon.
2. Click Run and then select Debug.
3. Right‐click on the .java file in the navigator, select Debug As, then Java application.
4. Press F11 on your keyboard.
Eclipse will ask if you would like to switch to the Debug perspective. Select Yes and your layout will
change. See Figure 6-11.
You will still see the Errors class and the outline and console look the same as the normal Java perspec-
tive. In addition, you will see at the top the Debug window and the names and values of the variables
in your program. One thing to keep in mind is that the variables displayed depend on the method your
program is currently inside and how much of that method has already been executed, so you can see the
variables from the main method until just before the for loop, since this is your first breakpoint.
The program is paused here, waiting for your instructions. To control the execution, you can use the
buttons built into Eclipse or the F5-F8 keys on your keyboard.
Search WWH ::




Custom Search