Build Winning Teams with iMocha

Company News, Diversity & Inclusion, iMocha Engineering Product Updates Remote Hiring Skills Assessment

All Posts

Whether you're an interviewer or an interviewee, what's required is preparation. 

Here is a comprehensive list of important java scenario based interview questions for experienced professionals based on Core Java concepts, OOPs, Collections, JVM, JDBC, Design Patterns, J2EE, Spring, and Hibernate.

Java Interview Questions for Experienced on Core Java

    1. Why the main method is static? Can we execute a program without the main() method? If yes, how?
    2. What if the static modifier is removed from the signature of the main method?
    3. Why static method cannot be overridden in Java?
    4. Explain Autoboxing. When do autoboxing and unboxing occur in Java?
    5. When do you favor abstract class over the interface?
    6. How are interfaces useful, and how are they abused? Narrate one or two ways you've used them.
    7. Why do you need a marker interface in Java?
    8. What will be the initial value of an object reference, which is defined as an instance variable?
    9. Why is string immutable in Java?
    10. Explain the scenarios to choose between String, StringBuilder, and StringBuffer?
    11. What are the benefits of the immutable objects? Why do you use them, and in which scenarios should you use them?
    12. Can you explain what does substring method do?
    13. Why compareTo() should be consistent to equals() method in Java?
    14. Will two object always be equal when their compareTo() method returns zero?
    15. How do you avoid NullPointerException while comparing two Strings in Java?
    16. When do Double and BigDecimal give different answers for equals() and compareTo() == 0?
    17. What is the purpose of a default constructor? When must the developer provide the constructor explicitly?
    18. Is it possible to call a constructor from another (within the same class, not from a subclass)? If yes, how?
    19. Why do you use threading? What are some of the drawbacks of threading?
    20. Tell me about frameworks you've used to manage to thread?
    21. How do you manage data that needs to travel across threads?
    22. When InvalidMonitorStateException is thrown? Why?
    23. How to detect a Deadlock in Java?
    24. How will you take a thread dump in Java? How will you analyze a thread dump?
    25. How can you trace whether the application has a thread leak?
    26. Is synchronization an overhead? If yes, how?
    27. What is busy spinning? Why should you use it?
    28. How busy spinning is useful and how can it be implemented in java in a multi-threaded environment?
    29. How to avoid busy spinning in Java?
    30. What is the use of volatile keyword? When should we use volatile variable in Java?
    31. What is the use of transient keyword?
    32. What is the difference between CyclicBarrier and CountDownLatch in Java?
    33. Give us scenarios when you will use CyclicBarrier.
    34. Are the wait, notify, and notifyAll methods in Object class?
    35. Why isn't thread class final? Why should one extend thread?
    36. Why thread communication methods wait(), notify(), and notifyAll() are in Object class?
    37. Why wait(), notify() and notifyAll() methods have to be called from synchronized method or block?
    38. Why are thread sleep() and yield() methods static?
    39. How can we achieve thread safety in Java?
    40. What is BlockingQueue? How can we implement Producer-Consumer problem using Blocking Queue?
    41. What happens if an exception is thrown in finally block? Is the remaining finally executed or not?
    42. Provide an example how inheritance can break encapsulation?
    43. Explain how cloning of mutable object works.
    44. Explain scenarios when we use shallow copy and when go for deep copy.
    45. Why is object clone() method available only to classes that implement Cloneable interface?
    46. Which objects should be called immutable?
    47. Why should you make an object immutable?
    48. If we have a class with all static members, is it immutable?
    49. Tell me about different reference types available in Java, e.g. WeakReference, SoftReference, or PhantomReference? Why should you use them?
    50. Can you list some of the methods in java lang Object?
    51. What are the different access specifiers in Java Language?
    52. Can you list primitive data types in Java?
    53. What is a ternary operator in Java? Have you used it?
    54. In the Java util package, what are the most important interfaces and objects?
    55. What is the difference between Java Development Kit (JDK), Java Runtime Environment (JRE), and Java Virtual Machine (JVM)?

Also Read: How iMocha’s Online Java Programming Tests can Help You Save $1200 Per Hire? 

Java Interview Questions for Experienced on Collections:

  1. Where will you use ArrayList and where will you use LinkedList?
  2. What is HashMap? Why do you use it?
  3. How does get () method of HashMap work in Java?
  4. When you are writing equals() method, which other method or methods you need to override?
  5. What will be the problem if you don't override hashcode() method?
  6. Where have you written equals() and hashCode in any of your projects?
  7. Is it possible for equals() to return false, even if contents of two Objects are same?
  8. What will happen if two different objects have the same hashcode?
  9. How will you retrieve value object if two keys have the same hashcode?
  10. What happens on HashMap in Java if the size of the HashMap exceeds the given threshold defined by load factor ?
  11. What is ReadWrite Lock? Does ConcurrentHashMapusesReadWrite Lock?
  12. State implementation of ReadWriteLock with different policies.

Java Interview Questions for Experienced on JVM:

  1. What are the different class loaders used by JVM?
  2. Is it possible to load a class by two ClassLoader?
  3. How many types of memory areas are allocated by JVM?
  4. How JVM Performs Thread Synchronizations?
  5. How to Profile Heap Usage?
  6. How do you identify minor and major garbage collection in Java?
  7. What is the difference between ParNew and DefNew Young Generation Garbage collector?
  8. If Object A has reference to Object B and Object B has reference to Object A, apart from that there is no live reference to either object A or B, are they eligible for Garbage collection?
  9. Does Garbage collection occur in permanent generation space in JVM?
  10. How can you control size of PermGen space?
  11. What are the best approaches to deal with OutOfMemeryError?
  12. How do you monitor garbage collection activities?
  13. Provide a Garbage collection output shown as below and prepare questions to ask a Java developer based on GC output:



[ParNew: 1512K->64K(1512K), 0.0635032 secs]

15604K->13569K(600345K), 0.0636056 secs]

[Times: user=0.03 sys=0.00, real=0.06 secs]

  • Is this output of Major Collection or Minor Collection?
  • Which young Generation Garbage collector is used?
  • What is the size of Young Generation, Old Generation and total Heap Size?
  • How much memory is freed from Garbage collection?
  • How much time is taken for Garbage collection?
  • What is current Occupancy of Young Generation?
  1. Should one Pool Object to help Garbage Collector? Should one call System.gc() periodically?
  2. Why Java based GUI intensive program has Performance Issues?
  3. There is a garbage collector alright, but then is memory leak totally absent in Java applications? If not, how so?

Java Interview Questions for Experienced on JDBC

  1. What are database warnings, and how can I handle database warnings in JDBC?
  2. Connected vs Disconnected RowSet, which one should I use and when?
  3. Why do we need a JdbcRowSet like wrapper around ResultSet?
  4. How JDBC work with REF CURSOR returned by the stored procedure and retrieve results?
  5. What is “dirty read” in JDBC? Which isolation level prevents dirty read?
  6. How to invoke Oracle Stored Procedure with Database Objects as IN/OUT?
  7. When do we get java.sql.SQLException: No suitable driver found?
  8. What are JDBC Best Practices?
  9. What is JDBC Driver?

  10. What are the steps to connect to a database in java?
  11. What are the JDBC API components?

  12. What is the role of the JDBC DriverManager class?

  13. What is the JDBC Connection interface?

  14. What is the purpose of the JDBC ResultSet interface?

  15. What is the JDBC DatabaseMetaData interface?

  16. What is the difference between execute, executeQuery, executeUpdate?

  17. What do you understand by JDBC Statements?

  18. What is the difference between execute, executeQuery, executeUpdate?

  19. What is the JDBC ResultSetMetaData interface?

  20. What do you mean by batch processing in JDBC?

Java Interview Questions for Experienced on Design Pattern:

  1. Which design patterns have you used? Explain how you used it with proper example and why you choose a particular pattern?
  2. Can you name a few design patterns used in standard JDK library?
  3. Which design pattern you will use to shield your code from a third party library, which will likely to be replaced in another couple of years?
  4. Do you know about Open Closed Design Principle or Liskov Substitution Principle?
  5. What is Singleton design pattern in Java? Write code for thread-safe singleton in Java.
  6. When doesn't Singleton remain Singleton in Java?
  7. What is lazy and early loading of Singleton and how will you implement it?
  8. What is double checked locking in Singleton?
  9. How do you prevent for creating another instance of Singleton using reflection?
  10. How do you prevent for creating another instance of Singleton during serialization?
  11. When to choose Singleton over Static Class?
  12. Can you replace Singleton with Static Class in Java? Describe to me a design pattern you used in a past solution and why that approach was appropriate.
  13. When using the Observer pattern, what approaches can be used by the subject so that its observers can be more efficiently updated?
  14. When and why would you favor the Decorator pattern over inheritance?
  15. How does the synchronized keyword make a method thread safe?
  16. Name the creational design pattern that is used to build complex objects step by step.
  17. What is the role of director in builder pattern implementation?
  18. Write an example to show how builder pattern can be applied.

Java Interview Questions for Experienced on Hibernate

  1. Why is it important to provide a default constructor in Java? What happens if your class doesn't have a no argument constructor?
  2. Explain hibernate architecture. (Dig more on this)
  3. What are the core interfaces of Hibernate?
  4. What role does the Session/SessionFactory interface play in Hibernate?
  5. What is the difference between get and load method? When to use them?
  6. How do you map Java Objects with Database tables?
  7. Give an overview of Hibernate and ORM.
  8. How do you load objects into the session?
  9. What does the session do with the objects while in the session?
  10. What is the difference between getting a persistent object from the session and querying for persistent objects?
  11. When is it better to use plain SQL instead of ORM?
  12. Why do we need ORM?

Also Read: Here's How To Hire Java Developer in Five Simple Steps

Java Interview Questions for Experienced on J2EE

  1. How do you prevent SQL Injection in Java Code?  (Java EE)
  2. Are you familiar with Session Fixation attack or Cross Site Scripting attack and how to resolve them?
  3. Is it good to have instance/static variables in a servlet? Why not? Then where do you store "state"? What & where is a "state" for a (web) application?
  4. What happens if I started creating/closing DB connections in "JSP"?
  5. What are the ways to handle JSP exceptions? try-catch? there anything else?
  6. Explain the various access modifiers used in Java. I have had lots of people struggle with this, especially default access.
  7. If you could change one thing about the Java language or platform what would it be?
  8. What is the general contract when overriding equals?
  9. Is better option to prefer lists or arrays?
  10. What are the generally accepted naming conventions?
  11. How does serialization work?
  12. How to implement Comparable?
  13. What are the advantages of using JDBC's Prepared Statements?
  14. What happens when an MDB encounters an exception that it cannot handle
  15. What are some ways for the client to obtain a reference to the DataSource from the app server?
  16. What is the difference between SOAP-based web services and REST-based web services?
  17. What exactly is REST?
  18. What is the purpose of each of the HTTP verbs?
  19. What is decoupling? Why are loosely coupled classes desirable? What are some drawbacks?
  20. What is cohesion? Why are highly cohesive classes desirable? What are some drawbacks?
  21. Describe polymorphism. What is the importance of contracts between interfaces and concrete types? Why is polymorphic code desirable? What are some drawbacks?
  22. If stuck in a situation where accessing a Hibernate/JPA POJO content leads to exceptions, how would one resolve it?
  23. How are dependent libraries packaged into an archive? Or the Visibility of various classes in a bundled archive.
  24. How could a simple web service be provided?

Java Interview Questions for Experienced on Spring 

    1. What are the types of IoC containers? Explain them.
    2. Why is dependency injection useful?
    3. Give an overview of how the Spring Dependency Injection container works?
    4. Give an example of BeanFactory implementation.
    5. What are the common implementations of the ApplicationContext?
    6. What is the difference between Bean Factory and ApplicationContext?
    7. What is an Annotation-based container configuration?
    8. How do you turn on annotation wiring?
    9. Explain the @Controller annotation.
    10. Explain @RequestMapping annotation.
    11. What are the differences between Spring MVC and Spring Web Flow?
    12. Tell us about the different types of Listener related events?

Questions to ask a Java developer (Senior) 

  1. What has been your experience with X, how did you use that?
  2. What challenges you had with X and how did you overcome them?
  3. Tell me some difficult problems you have solved and please tie that with the technologies you've listed on your resume.
  4. Provide a hypothetical architecture arrangement, and ask for insights on design considerations.
  5. Ask for an overview of processes when implementing a particular system in such a way your interviewee may demonstrate the "senior" part of the developer position.

Use this list of scenario-based Java interview questions for experienced professionals for interview preparation, or just peruse!


Rachana Mishra
Rachana Mishra
Growth Officer at iMocha

Topics: Tech Recruitment, Skills Assessment

Related Posts

iMocha Launches AI-EnglishPro To Empower Organizations To Build Winning Customer-facing Teams

iMocha has added to its amazing list of breakthroughs by releasing AI-EnglishPro, a new assessment tool that allows employers to objectively and accurately assess candidates' Business English competence. Recruiters and hiring managers can use AI-EnglishPro to evaluate candidates' Business English fluency and construct winning customer-facing teams in an unbiased, AI-powered, and simple method. The assessment tool is especially beneficial for university recruitment or campus hiring, lateral recruitment, and learning and development initiatives in an organization. 

iMocha is Changing its UI, and Here's What it Means For you

Last year, we rebranded us from Interview Mocha to iMocha, and with that we changed the way we look, the way we interact, and now it is time that change reflects our UI, too.