Beginner’s guide to Debug Java Code in Eclipse IDE

Supriya Ranjan
3 min readSep 21, 2021

--

What is Debugging

Debugging is the routine process of locating and removing bugs, errors or abnormalities from programs. It’s a must have skill for Java developers. Debugging allows us to run a program while watching a source code and the variables during the execution.

Eclipse IDE is one of the most preferred for Java developments. It allows you to start a Java program in Debug mode.

Beginner’s guide to debug a simple Java program in Eclipse IDE:

  1. Setting Breakpoints: To define a breakpoint simply point at the left margin near line number of variable or code that you want to debug and check the code flow. Then right click and select “Toggle Breakpoint”, or simply double click

2. Starting the Debugger: Here in following example for code debugging, I am trying to get the value of variable “JobLocation”. Now select Run>Debug or press F11.

3. A dialog box will appear asking to switch to Debug prospective. Select Switch and click.

4. The project will be changed to Debug prospective. The prospective can also be changed by selecting “Debug Prospective” in top right of Toolbar “Open Prospective ”.

5. We can check the value of current variable by hovering the arrow on it. Notice the value of variable “JobLocation ” is still empty.

6. Now Select RUN>Step Over, it will move the stack flow to next Step. Continue and keep checking variable values. Here now the value for variable “JobLocation” is displayed by hovering over it, that means program flow was bug free till this Line number. Same way you can continue the program flow step by step and locate which Line number or Code is causing the error.

7. You can also view values of all the variables in the right side of the screen, under “Variables” table. You can also double click over the values and change them for debugging purpose.

8. The “Breakpoints” can be Group by or Sort by , by right click on Breakpoint table.

9. RUN>Terminate to stop the debugging. And then change the prospective back to Java

--

--