As programs become more and more complex, the debugging process becomes more challenging. To help meet this challenge, you can use the Eclipse Java Debugger. Debuggers can help you diagnose problems that are hard to see by looking at the output or reading through the code. Invest some time now in learning this tool; it will pay benefits later when you’re debugging more complex programs.
The key feature that debuggers provide is the ability to stop the expectation of your program at selected points and to step through the statements one at a time, checking the value of variables as you go.
Start by setting a breakpoint at a suitable place in your program. Do this by clicking mouse-right on the gray bar to the left of your code in the editing window and choosing “Toggle Breakpoint”. The result will look something like this:
Note the small blue/aqua circle to the left of the
switch statement. This
indicates that the debugger has set a breakpoint at this statement.
In the middle of the debugger view, you’ll see a code window with the
switchstatement highlighted. This means that the debugger has stopped execution of the program just before running this statement. You may have to input data or do other user interface actions before the code gets to this point. You may now do any of the following:
Data Inspection - Inspect data values using the “Variables” window on the upper right. Some of the data values may be internally complex; in this case the data window will provide a hierarchical view of the data objects.
I/O - Perform I/O as required by the program either in the GUI or in the “Console” window at the bottom as appropriate.
Debug and Java Views -Switch back to the standard “Java” view to modify the program using the “Java” button in upper right.
There are more features to the debugger, but these will be most immediately useful.
Back to the top of this page