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.

To debug a program in Eclipse

  1. 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:

    setting a
		  breakpoint in eclipse

    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.

  2. When the execution of the program reaches a breakpoint, the debugger will stop execution and bring up this debugger view:
		  the debugger in eclipse
    In the middle of the debugger view, you’ll see a code window with the switch statement 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:

There are more features to the debugger, but these will be most immediately useful.

Back to the top of this page