What are the scenario based Java interview questions you have come across?

For me the most important part is not knowing/handling dubious code constructs, but more - choosing good long term approach, so an answer like “I would likely fail to solve such issue this time, but do this and that to be able to solve it next time it occurs” is totally fine.

Since during the interview I need to find out how would a person behave in real world situation I tend to ask “what would you do if” questions about typical cases when working with generic Java app.

For me the most important part is not knowing/handling dubious code constructs, but more - choosing good long term approach, so an answer like “I would likely fail to solve such issue this time, but do this and that to be able to solve it next time it occurs” is totally fine.

Questions:

  1. You have a Java web server in production that got stuck: stopped writing logs and doesn’t answer to http requests. How would you investigate?
  2. Logs say OutOfMemoryError - how would you investigate?
  3. Customer clicks on a button and gets NullPointerException, but same case works correctly in development environment. There are no log statements in code that help analyse the problem. How would you investigate and what step would you take to ease debugging such problems in future?
  4. You are investigating an issue and written a JUnit test - it fails as expected. So you start debugger and step over several times, but the issue is not reproduced. Why can this happen?
  5. Your production Java web server typically handles http request in <50ms, but now you see times raised to about 1 second. How would you investigate?
  6. You have multithreaded app which looks properly synchronized, but sometimes it seems that when particular field is read it returns old value. You suspect some synchronization issue, how would you investigate?