Eclipse Debugging
Debugging Java Programs
We can debug Java programs in the Package Explorer view with the following steps:
Right-click the Java class containing the main function
Select Debug As > Java Application
This action can also be performed using the shortcut keys Alt + Shift + D, J.
These steps will create a new Debug Configuration and use this configuration to launch the Java application.
If the Debug Configuration has already been created, you can select the corresponding class from the Run menu, choose Debug Configurations, and click the Debug button to launch the Java application.
The Debug menu item in the Run menu can reload the previously debugged Java application.
The shortcut key for reloading a previously debugged Java application is F11.
When starting a Java program in debug mode, the user will be prompted to switch to the debug perspective. The debug perspective provides additional views for troubleshooting the application.
The Java editor can set breakpoints for debugging. Right-click the marker bar in the editor and select Toggle Breakpoint to set a breakpoint.
Breakpoints can be seen in the marker bar and also in the Breakpoints View.
When the program execution reaches the code marked by the breakpoint, the JVM will suspend the program, allowing you to inspect memory usage and control program execution.
When the program is suspended, the Debug view can inspect the call stack.
The Variables view can display the values of variables.
The Run menu includes options to resume execution (Resume), step over a line of code (Step Over), and step into a function (Step Into).
The images above show the associated shortcut keys for actions like Resume, Step Into, and Step Over.