JDB Stepping with Introduction, JDB Tutorial, Architecture, Installation, Expression, Connection, Commands, Example, Breakpoint, Stepping, Options, Exception Handling etc.
Stepping is a very common method of debugging that executes the code line by line. So, this approach can be used when there is a requirement to check one line at a time. It simply controls the flow of program.
Techniques of Stepping
There are three techniques of stepping:-
- Step Over
- Step Into
- Step Return
In this approach, the particular line where the program is paused will get executed and now the program will paused on the next line.
In this technique, debugger entered into the method and start debugging line by line by using step over approach.
Once the method is debugged, step return is used to exit the control of program from that particular method.
Through this example, we will try to understand the JDB stepping.
- public class JStep
- int square(int a)
- return a*a;
- public static void main( String...jtp)
- JStep obj=new JStep();
- System.out.println("Square of given number : "+obj.square(4));
- Compile the above program and create a JDB session.
- Now, set the breakpoints.
- Run the debugger by using the following command: -
- >run JStep
Now use the following command to step up the execution to next line: -
Then use the below command to find out the position where the control has been reached.
- > list
If you notice in the below screenshot, the arrow (=>) indicates the current position of program control.
To continue the execution of code follow the below command