JDB Interview Questions and Answers for internship

100 JDB Internship Interview Questions and Answers
  1. What is your understanding of JDB (Java Debugger)?

    • Answer: JDB is a command-line debugger for Java applications. It allows developers to step through code, inspect variables, set breakpoints, and analyze program execution in detail. It's a powerful tool for identifying and resolving bugs.
  2. How do you start JDB?

    • Answer: JDB is typically launched from the command line. The exact command depends on the JVM and how the application was launched (e.g., using `jdb -attach ` to attach to a running process or specifying the class file to debug when launching). You'll need to provide the classpath as well.
  3. Explain the `stop at` command in JDB.

    • Answer: The `stop at` command in JDB sets a breakpoint at a specific line number or method within your Java code. Execution will pause when the program reaches that point, allowing you to inspect variables and the program's state.
  4. How do you list methods in a class using JDB?

    • Answer: You can use the `methods` command in JDB followed by the class name. For example, `methods MyClass` will list all the methods within the `MyClass` class.
  5. What is the purpose of the `step` command?

    • Answer: The `step` command executes the current line and then pauses, allowing you to step through the code line by line. If the current line calls a method, execution steps *into* the called method.
  6. What is the difference between `step` and `next` commands?

    • Answer: `step` steps into method calls, while `next` steps *over* method calls. `next` executes the entire called method without stepping into it.
  7. How do you set a breakpoint at a specific line using JDB?

    • Answer: Use the `stop at` command followed by the class name, line number. For example, `stop at MyClass:15` sets a breakpoint at line 15 of MyClass.
  8. How do you list all breakpoints in JDB?

    • Answer: The `stop` command (without any arguments) lists all currently active breakpoints.
  9. How do you disable a breakpoint in JDB?

    • Answer: You can use the `clear` command followed by the breakpoint number to disable it. You obtain the breakpoint number using the `stop` command.
  10. How do you delete a breakpoint in JDB?

    • Answer: Use the `clear` command followed by the breakpoint number to delete it permanently. This is different from disabling.
  11. How do you examine the value of a variable in JDB?

    • Answer: Use the `print` command followed by the variable name. For example, `print myVariable` will display the value of `myVariable`.
  12. Explain the `locals` command in JDB.

    • Answer: The `locals` command displays the values of all local variables currently in scope.
  13. How do you resume execution after pausing in JDB?

    • Answer: Use the `cont` (continue) command to resume program execution until the next breakpoint is encountered or the program terminates.
  14. What does the `where` command do in JDB?

    • Answer: The `where` command shows the current call stack, indicating the sequence of method calls that led to the current execution point.
  15. How do you use JDB to debug a remote application?

    • Answer: This involves starting the remote JVM with appropriate options for JMX or RMI and then using JDB's `attach` command to connect to the running process. The specifics depend heavily on the setup.
  16. Describe the use of watchpoints in JDB.

    • Answer: Watchpoints pause execution when the value of a specific variable changes. This is useful for tracking down subtle bugs related to variable modification.
  17. What are some common pitfalls when using JDB?

    • Answer: Common pitfalls include forgetting to include the necessary classpath, incorrect breakpoint specifications, difficulties debugging multi-threaded applications, and the command-line interface's learning curve.
  18. How can you debug a deadlock using JDB?

    • Answer: By using the `threads` command to see the state of all threads, identifying which threads are blocked, and then using the `where` command on the blocked threads to examine their call stacks to pinpoint the source of the deadlock.
  19. What is the significance of the classpath when using JDB?

    • Answer: The classpath tells JDB where to find the necessary class files for the application being debugged. Without a correct classpath, JDB cannot load the classes and will result in errors.
  20. How would you use JDB to inspect the contents of an array?

    • Answer: You would use the `print` command, but you might need to iterate through the array elements using a loop within JDB's command-line environment or use a more sophisticated approach depending on the array's complexity and the JDB version.

Thank you for reading our blog post on 'JDB Interview Questions and Answers for internship'.We hope you found it informative and useful.Stay tuned for more insightful content!