Eclipse Banner Eclipse IDE Debugger Tutorial

Adapted from a tutorial at the University of Wisconsin

The Eclipse Debugger is a tool that you can use to analyze your program while it's running.

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 behavior (output) should be.
  3. Design a test that fails due to the bug. (I.e., a set of actions that can reliably reproduce the failure/bug. For example, "if I enter a number less than zero, I should get 'happy', but instead I'm getting 'sad'.")
  4. Identify one or more sections of code (or variables) that control that aspect of your program. (Continuing our example, look for code that prints "happy" or "sad". That's a possible starting point.)
  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 re-run the test from step 3.
  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 and what might be causing it.

This tutorial guides you through the basic functions of the Eclipse debugger. We will use as an example a small project that 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 (or use this zip file and decompress it).

  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. (Aquarium is the main class.) 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