Disclosure: This article may contain affiliate links. When you purchase, we may earn a small commission.

Top 17 Interview Questions to Test Debugging Skill of Java Programmers

Hello guys, if you are a beginner or an experienced Java developer with 1 to 3 years of experience under your belt, when you go for a Java interview you should prepare some Java debugging interview questions like how to debug a Java program running in Linux environment etc. In the past, I have shared 130+ core Java questions, 50+ Multithreading Questions, 25+ Java Collection questions and 50+ Lambda and Stream interview questions and in this article, I am going to share 17 questions to test debugging skills of Java programmers. While a couple of questions are Java related but many questions are also based upon problem solving and general debugging skill which can be used to test any programmer like Python, JavaScript or C++ programmer. 

Apart from coding, One of the most important skill of a programmer is debugging or troubleshooting. I have often found that good programmers are also good problem solver, troubleshooter and debugger. Any problem arise in production or development environment, a good programmer can look it quickly, find the root cause and has solution ready to minimize the impact. 

That's why I advised all interviewers to pay more attention to the debugging skills of Java programmers during interviews. A good debugging skill shows many things, it shows reasoning skill of candidate i.e. if one thing is not working where to look, what could be wrong, it also shows overall knowledge and experience. 

Similar to coding, You just can't fake debugging skill. You learn it the hard way by doing and understanding what you are doing. In order to be a good troubleshooter, you should also have sound knowledge of OS, networking, programming fundamentals, Java, JVM and other products, tools, commands and environment your process is running. 

Now, question is how do you test the debugging skill of Java programmers during interviews? Well, the traditional way is to ask questions and analyze his answers and cross question, because that's how you troubleshoot or debug problems. In this articles, I am going to share some common debugging questions related to core Java and Java Web applications running on Linux.



17 Java Debugging Interview Questions with Answers for Beginners and Experienced Programmers

Here is my list of Java interview questions to test the debugging skill of any Java programmer or developer. The list not only focus on Java centric questions like how to take heap dump and thread dump of Java application for debugging and troubleshooting but also features general problem solving questions which can be used to test debugging skill of any programmer like what will you do if suddenly your application become slow in production? what you will check and where you will check etc?

So what are we waiting for let's start:

1) Suppose your program is a core Java application e.g. a FIX engine, which listens on a port, how do you know that your program is running or not?
Answer : Assuming your Java application is running on Linux or Windows, you can use the telnet command to check if its up or not. if you connect to the application via given host and port than its up, otherwise its down. 

2) How do you get the IP address of host from DNS name e.g. myJavaApplication.asia.com?
You can simply ping to that domain name or you can use the nslookup command to find the IP address associated with that domain name.

3) How do you find all the ports on which your Java application is running?
You can use netstat -nap command and grep with the PID of Java application. It will list all the connections, from there you can see on which port it is listening. 

4) How do you take the thread dump of Java process?
If your Java application is running on UNIX than you can use kill -3 to take the thread dump. By the way, if you are using tools like Visual VM or IBM Thread Dump Analyzer for Java then you can also use them to take thread dump of any JVM. 

Top 17 Interview Questions to Test debugging Skill of Java Programmers



5) How do you send the HTTP request from UNIX?
You can use curl or wget command to send the HTTP request from Linux.

6) How do you find the command line arguments of your Java process?
You can check the config if you know for sure otherwise do a ps -ef | grep "identifier" to see the command line arguments of your Java application. 

7) How do you find all the files associates with your Java process?
You can use the lsof command to list all the files currently opened or associated by your Java process.

8) Suppose your Java application is hosted on tomcat and its not responding to requests how do you troubleshoot?
First check whether tomcat is up or not, than check whether your application is loaded successfully or not. You can check your application log file and catalina.out log files. Than check whether your request is reaching to server or not, if not then something is wrong with your request e.g. typo on host or port, also it could be problem with firewall and network connection from your client machine to server machine. If your request is reaching to server then check where its getting stuck e.g. does it trigger a database hit and your request is getting stuck there, or it triggers a file load. Step by Step tracing is the way to go.

9) What is remote debugging in Eclipse or IntelliJIDEA?
remote debugging allows you to connect to the Java program running on a remote host. If your JVM is started in debug mode than you can connect to it from Eclipse or IntelliJ Idea to remote debug it. Sometime this is the only way to debug a legacy application which is difficult to setup in your Windows machine or have dependency on native libraries which is not available for Windows.

Java debugging interview questions with answers



10) How do you find CPU and memory used by your Java application?
You can use commands like top, free in Linux to find CPU and memory profile of Java application. You can also use prstat command in Solaris to get the same. 

11) What is difference between ClassNotFoundException and NoClassDefFoundError?
Both the problems are associated with missing JAR files on classpath but ClassNotFoundException suggest that class is loaded dynamically e.g. by passing String name e.g. JDBC driver which you load by calling Class.forName() method, while NoClassDefFoundError suggest that class is statically linked to another class, was present at compile time but now not available at runtime. It usually comes when a particular class was not loaded due to error in static initializer block. 

12) How do you take heap dump during OutOfMemoryError of Java application?
By specifying JVM option -XX:HeapDumpOnJavaOutOfMemoryError. You can later use tools like Java Visual VM or  Eclipse Memory Analyzer to analyze heap dumps

debugging interview questions with answers



13) Your Java application loads data from database but is suddenly getting stuck while starting up? how do you find the root cause and how to solve?
You can first check the log file to see at which step your application is getting stuck. If application loads lot of data from database during startup and its getting stuck there than check if database is available or not. Generally if database is not available than you will see JDBC errors in log file, if you are not seeing them it means you are able to connect to database but your query is blocked at DB end. Check your DB for blocked SQL queries or ask DBAs. 

14) How do you find which object is taking most of the memory allocated to your Java application?
Take a heap dump and analyze it using hprof tool.

15) What is breakpoint? How do you see the variable's value at breakpoint?
When you debug your Java application in IDE's like NetBeans, Eclipse and IntelliJ, you can setup breakpoints on any line of code. Once your application that line of code it will stop, from there you can control the execution by execution one step at a time  using Step Into, Step Over and Step Return options. You can either use Inspet or watch to see the values of variables.

16) How do you find out if there is a memory leak in your Java application?
If you see the memory continuously growing in your Java application even after garbage collection than there is good chance that your application is keeping objects which is not needed, hence causing memory leak. You can take heap dump or profile your application get further information e.g. which objects are not feeing up memory. ThreadLocal variable often cause memory leak in Java application. 

Java debugging interview questions with answers for 3 to 5 years experienced



17) How do you profile your application?
You can profile your application by using a profiler e.g. NetBeans profiles which comes with NetBeans IDE. There are also some commercial profilers like YourKit and JProbe, which you can use to profile your Java application. 


That's all about 17 Java debugging and troubleshooting interview questions for beginners and experienced programmers. You can use these questions to test the debugging skill or a Java programmer who has to support a Java application running on Linux machine. You can fine tune questions to include more questions from JVM, Garbage collection, networking and your current application architecture.

Other Java Multi-threading Interview Questions you may like to explore
  • 10 Java Synchronization and Locking Interview questions (locking questions)
  • Top 5 Courses to learn Multithreading and Concurrency in Java (courses)
  • 25 DevOps Interview Questions with Answers (devops questions)
  • Top 12 Java Concurrency Questions for Experienced Programmers (see here)
  • Top 10 Courses to learn Java in-depth (courses)
  • Top 15 Multithreading and Concurrency Questions from Investment banks (see here)
  • How volatile variable works in Java? (answer)
  • Top 5 Books to learn Java Concurrency in-depth (books)
  • Top 10 Java Concurrency and multi-threading best practices (article)
  • Difference between start() and run() method in Java? (answer)
  • Top 5 courses to Learn Java Performance Tuning (courses)
  • 10 Courses to Crack Java Interviews for Beginners (courses)
  • What is happens-before in Java Concurrency? (answer)
  • 6 Books to learn Multithreading and Concurrency in Java (books)
  • 10 Advanced Core Java Courses for Experienced programmers (course)

Thanks for reading this article. If you like this post then please share it with your friends and colleagues. If you have any suggestions or feedback then please drop a comment. Btw, if you think that Java Concurrency in Practice is not relevant in the era of Java 8, then please read this article before making your judgment. 

No comments :

Post a Comment