JDB Breakpoints - The Java Debugger (JDB)

What is JDB Breakpoints?

This section clarifies the idea of breakpoints and in what way to set breakpoints in a program. A breakpoint announces an obvious stop or pause in the execution of a program at a specific line of code while debugging. It is valuable to obtain knowledge about variables in the program in its execution.


The following command sets up a breakpoint at a particular line number:

The resulting command sets up a breakpoint on a particular method or on a particular variable:


The resulting instance shows how to set up a breakpoint in a class.

Save the above file as Add.java. Compile this file using the following command:


Let us take an instance for debugging. Now, we start the debugging procedure by setting up a breakpoint on main (). Given underneath are the steps to be followed in the debugging process:

Step 1: Start a JDB Session

The following command starts a JDB session on the Add class for debugging:

Step 2: Set a Breakpoint

The resulting command sets up a breakpoint on the main() method of Add class.

If the breakpoint is set magnificently, you get to see the following output:

Step 3: Start Debugging

The following command starts execution of the class Add:

If you execute this command, you get to see the resulting output. In this output, you find that the execution stops at the breakpoint position, that is at the main() function.

The execution stops at the first line of the main method, that is at "int a=5, b=6;" or Line no: 11 in the code. You can observe this information in the output.

Step 4: Continue Execution

The following command continues the program execution:

It provides you the remaining execution part and output as follows:

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

The Java Debugger (JDB) Topics