Using the Debugger in Eclipse

>> Debugger

Introduction

When I started as a Java Developer, I rarely made use of the debugger in Eclipse. I had vague memories of using a debugger in my undergrad in a class on the Pascal programming language back in the 90's. I can't tell you about the debugger I used, and I can't even tell you if I used an IDE for that class. But ever since then I had always been using output statements ("sysouts") to track program progress and to output the state of variables at each sysout. Because the complexity level of the code I worked on was fairly moderate, I was able to get by on using this technique alone.

But very soon after working with other Java Devs I was introduced to using the debugger in Eclipse. I learned how to use the debugger slowly, step by step, until I had become competent in using it. However, I also learned that setting up "breakpoints" in code, stepping through the code and drilling down into deeply nested object values was not always as fast as just throwing into the code a sysout with all the variable values I needed in one quick spot.

So with that caveat, let me explain how to use the debugger in Eclipse. It truly enhances your ability to track what is going on in your code. I will assume here that you don't know anything about the debugger. I will also start with using the debugger for Java, for a Java Application (not yet for using it with a web server).


>> Find the Debugger

Eclipse Menu Run

Run Menu

To find the debugger, there are several locations in Eclipse that will take you there. The first is the "Run" menu. It is great because it allows you to Run or Debug programs, control "breakpoints", "watch" and "inspect" variables as you step through a program, and more. Notice below that the keyboard shortcuts are listed alongside the menu options. This comes in handy when "stepping" through the code line-by-line, discussed here later on. Also notice that some of the images shown below to the left of the menu item also appear on the main toolbar, including "Resume" (aka start, F8), "Terminate" (aka stop), "Step Into" (F5) and "Step Over" (F6). Remember this for the "breakpoints" section below.

Run Menu