How to Debug a Java Project in Eclipse?
Last Updated :
24 Dec, 2022
Every Java developer needs to work in Debug mode to resolve the errors. Experienced Java developer already knows how to debug the code but if you are new as a Java developer this article will cover the topics which help to debug the code faster in eclipse and also use the "Debug Mode" efficiently and efficiently. Let's understand some terms to begin.
What is Debugging?
Debugging is one of the broadest topics in Software Engineering. It is a process to find subtle and remove bugs, and errors, and to understand the flow of the code as well. It is a must-have skill for all Java developers because debugging can help in locating the bugs which are not visible during code reviews. Let's discuss the steps to debug the code in eclipse.
Step by Step Implementation
Step 1: Start with setting Breakpoints
First, we need to set breakpoints in the code to stop the execution at your desired location. While running the program in debug mode it will temporarily stop execution at a particular point in the code. So, there are some ways to set breakpoints in code.
- First, is to put the cursor on a line in code which you want to set as a breakpoint then press Ctrl+Shift+B.
- Second, is to double-click on the left margin or right-click in the editor and select "Toggle Breakpoint".
You will see a blue dot will appear next to that line.
Step 2: Activate Debug Mode
Now to debug the project have different ways in Eclipse.
First, right-click on the project which you want to debug and select "Debug As" then "Java Application".
Eclipse asks you want to switch to the Debug Perspective once the compiler reached the first breakpoint. Like the below image
Once you click on Switch, you will see Debug Mode in eclipse.
Second, on the right corner of the eclipse editor have an Icon debug double Click on it.
You will observe that debug mode is activated. Like the below image.
On the right side, in the "Breakpoints" section you can see a list of all the Breakpoints which has been set for you.
Step 3: Control the flow of Execution
In the toolbar of Eclipse editor appears several buttons for controlling the flow of execution of the program.
To control the flow of execution eclipse provide the most commonly used buttons are:
Button Name | Short-Cut key | Purpose |
Resume | F8 | Execution of the program until the next breakpoint is reached. |
Terminate | Ctrl+F2 | To stop the execution of code. |
Step Into | F5 | Executes the current line of code and goes to the next line of code. |
Step Over | F6 | Executes the current line of code and goes back to the previous line. |
Conclusion
For every Java Developer having good debugging skills is necessary. it can be got by practice there are not any particular techniques to learn and get the debugging skills for that you need to spend more time and learn the different views of debugging this article is for beginners who are just starting their journey as Java developers. Hope this article helps and start your debugging journey.
Similar Reads
How to Create a Maven Project in Eclipse IDE? Maven is a powerful project management tool that is based on POM (project object model). It is used for project build, dependency, and documentation. It simplifies the build process like ANT. But it is too much advanced than ANT. In short terms we can tell maven is a tool that can be used for buildi
2 min read
How to Create Jar File for Java Project in Eclipse? Java programmers already know about what is a jar file if you are new then first understand what is a jar file. Once you are completed your project in Eclipse the next task is to create a runnable version of your project. Eclipse support only exporting the JAR (.jar) file, not the Executable (.exe)
3 min read
How to Create a Project In NetBeans GUI? All Java Development in the IDE takes place within Projects, we first need to create a new project within which to store sources and other project files. An IDE project is a group of JAVA Source files plus its associated metadata (data about data), including project-specific properties files, and ma
2 min read
How to Run the Java Code in Git Bash? Git Bash is a command-line interface that provides a Unix-like environment on Windows. You can use it to compile and run Java programs just as you would in traditional terminals on Linux or macOS. Step to Run Java Code in Git Bash:1. Install JavaMake sure you have Java installed on your Windows comp
2 min read
How to Install Eclipse IDE For Java? There are many software been there such as IntelliJ IDEA, Eclipse, etc of which most developers are tilted towards using Eclipse is open-source software. It is mainly used for JAVA applications development. We can also use it to develop applications in various programming languages like C, C++, C#,
2 min read