Google News
logo
JDB Interview Questions
(JDB) Java debugger is a command line Java debugging tool used to debug Java programs without the requirement of inserting specific debugging instructions into the code.
These are some advantages of Java Debugger :
 
* It is a lightweight debugging tool.
* It is free to use and available for all type of operating systems.
* The execution of Java debugging tool is very fast.
* It provides support for multithreaded programs and remote applications.
These are some commonly generate bugs :
 
* Syntactical or Compilation errors : These errors are generally generated due to some typing mistakes.
* Run-time errors : These errors are generated at execution time generally due to exceptions.
* Threading errors : These errors are difficult to replicate and track down.
Several types of Java Debuggers are :
 
* Stand-alone debuggers such as JLike and JProbe.
* Command-line debugger such as Sun JDB.
* IDEs contain their own debuggers such as Borland JBuilder and IBM VisualAge for Java.
Various types of approaches used for debugging are :
 
* Optimized code debugging
* Using comments
* Basic Java bytecode (by using System.out.println() )
* Remote Debugging
* Debugging on demand
There are various ways to connect JDB with JVM, but the simplest one is to provide the following command at the runtime of your main class :

>jdb MainClass  

Here, MainClass represents the name of your class.
Java debugger interacts with the Java runtime interpreter to interrupt the normal flow of the program. Thus, Java interpreter provides support to the debugger.
The following syntax is required to invoke debugger :
 
jdb [options] [classname] [arguments]
 
To debug an applet, we have to execute the debugger within applet viewer by the help of the following command :
 
>appletviewer -debug URL

To start the execution of the main class, you need to execute the below command :
 
>run [class [args]]

It is optional to mention the name of specific class and argument.
Use the following command to complete the partial execution of the program.
 
>cont

The print command is used to display the value of expressions whereas dump command is used to display the information of objects.
Breakpoints are used in debugging to pause or stop the execution of a program at a specific line of code and test whether the program is functioning correctly or not.
A breakpoint can be set either on the basis of method name or the specific number of the line.
 
* To set a breakpoint on the method, the following syntax is used :

stop in Classname.MethodName  

* To set a breakpoint on the specific line, the following syntax is used :

stop at Classname: LineNumber
Let suppose there is an applet named as Javatpoint having a method scrollDown(). To set a breakpoint on scrollDown() method, you need to follow the below command :
 
>stop in Javatpoint.scrollDown

Yes, Java debugger is capable of handling runtime exceptions. To handle these exceptions it provides catch command.
In JDB, Stepping is a procedure to execute the code line by line. Thus, through this approach, each line of the code can be properly examined.
These are the following techniques of stepping :
 
* Step Over
* Step Into
* Step Return