You are on page 1of 4

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

You might also like