What is Debugging in Java

A debugger allows you to step through the program and look at the variables. Such debuggers are usually integrated into the IDE, but they work in a similar way everywhere. This is demonstrated here using the example of Eclipse.

Set breakpoint

In order to be able to step through the program, a stop is first required near the point where the debugger should stop so that the code can be stepped through.

To do this, click on the left in the column next to the row. With some systems a double click is necessary, with others a right click, whereupon a menu item appears with the creation of a breakpoint. The breakpoint can also be removed again in the same way.

Start the debugger

You start the debugger under the menu item, the [F11] key or by clicking on the small beetle to the left of the start button.

Eclipse switches to the debug perspective. To switch back later, you will find the switch between the perspectives at the top right. The highlighted one is the Java perspective, that with the Beetle is the debug perspective.

The screen now looks like this:

The source code is on the left. The current line is highlighted in green.

Above is the call hierarchy.

To the right are the variables with their values.

Navigate with the debugger

After Eclipse is in debug mode and the program has been stopped at the breakpoint, the following buttons are available:

The symbols are very similar on most debuggers, but the keys differ more often. Here are the buttons for Eclipse:

  • [F8] - Continue: Continue walking to the next breakpoint.
  • [Ctrl] + [F2] - Terminate: Stop the program.
  • [F5] - Step Into: Jump to the method call you are standing on.
  • [F6] - Step Over: Skip the method call you are standing on.
  • [F7] - Step Return: Run through to the end of the method and then stop.