Eclipse Banner Eclipse IDE Debugger Tutorial

The Eclipse Debugger is a tool that you can use to analyze your program while it's running. Be sure to read Chapter 10.6 and 10.7 of your text book before completing this tutorial.

A debugger is a useful tool, but it is no substitute for careful thought. Stepping through code in a debugger takes time. You should always have a debugging plan before you start up a debugger.

Sample debugging plan:

  1. Identify the problem (bug). State it as precisely as you can.
  2. Determine what the correct outcome (output) should be.
  3. Design a test that fails due to the bug.
  4. Identify one or more sections of code (or variables) that control that aspect of your program.
  5. Set breakpoints at or before the bug occurs and use a debugger to trace each section of code and view the variables and results until a variable's value or output is not as expected.
  6. Continue narrowing your search until you find the line(s) that do not produce the expected result.
  7. Edit those lines and run the test.
  8. Repeat these steps until all of your tests pass and you have no bugs.

If you find yourself stepping through a program with no idea of what you are trying to find out or with no idea of the correct execution, you are wasting your time. Spend some time away from the debugger thinking about the problem.

This tutorial guides you through the basic functions of the Eclipse debugger. We will use as an example a small project you can experiment with as you follow the steps of the tutorial.

Set up the tutorial project:

  1. Create a new project named DebugTutorial in Eclipse.

  2. Download the following files and add them to your project.

  3. Refresh the project listing to see the newly added files.

  4. Add javabook2.jar and tutorial.jar as external .jar files to your project.
  5. Refer to the Eclipse Tutorial: Step 4 for instructions on adding external jar files if necessary.

  6. Run the project before you begin the tutorial. The project is a very simple simulation of an Aquarium. When you are prompted, enter the following values:


  7. Choose Continuous Mode to see the simulation.

  8. Quit the simulation after you have witnessed each of these bugs:
    1. The incorrect number of fish are created.
    2. The food centers are not showing the correct food point values.

The following pages take you through the basic steps of using a debugger tool to find and fix these bugs. Select a topic to review, or click Start below to begin the tutorial.

  1. Switch to the Debug Perspective.
  2. Set one or more Breakpoint(s).
  3. Run the Debugger.
  4. Step Over a Method Call.
  5. Step Into a Method.
  6. Inspecting Variables.
  7. Step Out Of a Call to a Method.
  8. Review the Method Call Stack.
  9. Finish the Tutorial.

Start Tutorial