JDB Breakpoint with Introduction, JDB Tutorial, Architecture, Installation, Expression, Connection, Commands, Example, Breakpoint, Stepping, Options, Exception Handling etc
In JDB, breakpoint is used to pause or stop the program explicitly. The purpose behind this is to acquire the knowledge about a program during its execution.
The programmer inspects the test environment during this interruption to find out whether the program is functioning as expected.
Breakpoint can be set in a program in any of the following ways:-
Breakpoint can be applied in a program on the basis of line number. The below syntax is used for it.
- stop at <class name> :<Line number>
It sets the breakpoint at the first instruction of the specific line.
Breakpoint can also be applied on method or variable name. The below syntax is used for it.
- stop in <class name>:<method name|variable name>
It sets the breakpoint at the beginning of the method.
Note:- In the case of method overloading, it is required to specify the type of argument.
JDB Breakpoint Example
Through this example, we will try to understand the JDB breakpoint.
- public class JBreak
- public int cube(int a)
- return a*a*a;
- public static void main( String...jtp)
- JBreak obj=new JBreak();
- System.out.println("Cube of given number is : "+obj.cube(2));
Compile the above program by using the following command:-
- >javac JBreak.java
Then, initialize Java debugger with the following command:-
- >jdb JBreak
Now, set up a breakpoint on the cube() method with the help of following command:-
- >stop in JBreak.cube
fter the execution of this command, the following message will generate on console.
Deferring breakpoint JBreak.cube.
It will be set after the class is loaded.
- Start to debug the class with the following command:-
The following result will be generated on your console.
You can see that the execution stops at the cube method.
- Now, if you want the complete execution of your program with the desirable result then follow the below command to continue the execution.
Once the complete execution is completed, the following output will be generated on your console.