0% found this document useful (0 votes)
11 views4 pages

Eclipse Java Debugging Quick Guide

The document provides tips for debugging Java programs including running in debug mode, using breakpoints, the debug perspective, stepping commands, and watching/changing variable values.

Uploaded by

bmwli
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Eclipse Java Debugging Quick Guide

The document provides tips for debugging Java programs including running in debug mode, using breakpoints, the debug perspective, stepping commands, and watching/changing variable values.

Uploaded by

bmwli
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Eastern International University School of CIT

QUICK GUIDE TO START DEBUGGING.


1. What is debugging?

Debugging allows you to run a program interactively while watching the source
code and the variables during the execution.

Debugging is a fundamental skill of a programmer. The main purpose of debugging


is to find errors in the program, in addition, it also helps the programmer better
understand how the program works.

A breakpoint in the source code specifies where the execution of the program
should stop during debugging. Once the program is stopped you can investigate
variables, change their content, etc.

Here are some quick tips and tools that will help you get started quickly with
debugging your Java project.
2. Run a program in debug mode

• On menu bar -> Run -> Debug As -> Java Application.

• Right click on the class contain method main() -> Debug As -> Java Application.
• Click the Debug button -> Debug As -> Java Application.

• Press the key F11.


3. Breakpoints

A breakpoint is a signal that tells the debugger to temporarily suspend execution


of your program at a certain point in the code.
To define a breakpoint in your source code, right-click in the left margin in the Java
editor and select Toggle Breakpoint. Alternatively, you can double-click on this
position.

CSE 102 – Introduction to Programming


Eastern International University School of CIT

4. Debug Perspective

The debug perspective offers additional views that can be used to troubleshoot
an application like Breakpoints, Variables, Debug, Console etc. When a Java program
is started in the debug mode, users are prompted to switch to the debug perspective.
• Debug view – Visualizes call stack and provides operations on that.
• Breakpoints view – Shows all the breakpoints.
• Variables/Expression view – Shows the declared variables and their values.
Press Ctrl+Shift+D or Ctrl+Shift+i on a selected variable or expression to
show its value. You can also add a permanent watch on an expression/variable
that will then be shown in the Expressions view when debugging is on.
• Display view – Allows to Inspect the value of a variable, expression, or selected
text during debugging.
• Console view – Program output is shown here.

CSE 102 – Introduction to Programming


Eastern International University School of CIT

5. Stepping commands

The Eclipse Platform helps developers debug by providing buttons in the toolbar
and key binding shortcuts to control program execution.

• F5 (Step Into): Step into the call.


• F6 (Step Over): Step over the call.
• F7 (Step Return): executes the current statement and returns to the place
called this method.
• F8 (Resume): executes the current statement and jump to next breakpoint.
• Ctrl + F2 (Terminate): terminate debugging.
6. Watching the values of variables in the debug

If a Breakpoint is encountered, the program will stop for you to control and
monitor. As you can see, the program will stop at Breakpoint at line number 7:

CSE 102 – Introduction to Programming


Eastern International University School of CIT

7. Changing/assigning variable values during debugging


For example: start the above demo program, trying to change the value of
variable n by change its value as follow:

--------oooooENDooooo--------

CSE 102 – Introduction to Programming

Common questions

Powered by AI

Breakpoints are used in debugging to pause program execution at specific points of interest in the code, allowing the programmer to inspect the current state of the program, such as variable values and execution flow. This helps the programmer identify where errors may occur and understand how the program functions under different conditions .

Changing variable values during debugging allows programmers to test how different data impacts program execution and outcomes. It demonstrates program behavior under altered conditions without modifying the source code, providing insights into potential error conditions and logical paths not initially evident .

The Debug view in Eclipse visualizes the call stack, showing the sequence of method calls leading to the current point of execution. This allows developers to trace the path taken by their code, identify where control flow deviates from expectations, and locate the origin of errors in nested or recursive calls, thereby supporting error resolution .

Stepping commands enhance a developer's debugging efforts by allowing controlled execution through the code. Step Into (F5) helps enter functions to inspect deeper execution, Step Over (F6) moves over function calls to continue line-by-line analysis, Step Return (F7) exits functions while continuing flow insight, and Resume (F8) jumps to next breakpoint for broad flow control. This granularity helps pinpoint errors precisely in complex logical pathways .

The Console view in Eclipse's debug perspective displays program output, allowing developers to see live feedback and diagnostic messages from the code. This output can highlight errors, confirm expected actions, or provide insights into the flow of execution, aiding in effective debugging .

A programmer can control the execution of a program using stepping commands provided by the debugger. These include Step Into (F5), Step Over (F6), Step Return (F7), and Resume (F8), each allowing different levels of interaction with the code execution process .

The Eclipse IDE provides a debug perspective which includes various views such as Debug, Breakpoints, Variables, and Console. These views enable developers to monitor the call stack, manage breakpoints, inspect variable values, and view program output, thus facilitating thorough investigation and troubleshooting during debugging sessions .

Toggling breakpoints allows programmers to pause execution at critical code points, facilitating inspection of variables and application state during runtime. This is especially useful in complex algorithms or when trying to diagnose non-deterministic bugs where errors appear under specific conditions, allowing direct observation at suspect points .

In the Variables/Expression view, programmers can inspect variable values, evaluate expressions, and set watches on variables. This capability is crucial for real-time monitoring of program state and evaluating logical conditions and data flow within the application, thereby enhancing debugging effectiveness .

Adding a permanent watch on variables or expressions enables constant monitoring of changes to their values throughout the debugging session, aiding in identifying incorrect state transitions or unexpected modifications. However, excessive use of watches might clutter the debugging environment and distract from other insights, making it critical to use selectively .

You might also like