<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=555865791448670&amp;ev=PageView&amp;noscript=1">

Hire job fit candidates. Faster.

All Posts

java_interview_question

Looking for Java interview questions?

Here is the list of most important questions on Core Java Concepts, OOPs, Collections, JVM, JDBC, Design Patterns, J2EE, Spring, and Hibernate.Make yourself ready with the Java interview questions.

Interview Questions on Core Java:

    1. Why main method is static? Can we execute a program without 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 autoboxing and unboxing occur in Java?
    5. When do you favor abstract class over the interface?
    6. How interfaces are useful, how they're abused?Narrate one-or-two ways you've used them.
    7. Why do you need 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 immutable object, why do you use them and 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. Does two object will 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 default constructor? When must developer provide 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 threading?
    21. How do you manage data which needs to travel across threads?
    22. When InvalidMonitorStateException is thrown? Why?
    23. How to detect a Deadlock in Java?
    24. How will you take thread dump in Java? How will you analyze Thread dump?
    25. How can I 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 to use the 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 would I extend Thread, ever?
    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 Thread sleep() and yield() methods are 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 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 type available in Java, e.g. WeakReference, SoftReference or PhantomReference? Why should you use them?

 

Interview Questions 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 works 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 your project?
  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 will have the same hashcode?
  10. What happens On HashMap in Java if the size of the HashMap exceeds a given threshold defined by load factor ?
  11. What is ReadWrite Lock? Does ConcurrentHashMapusesReadWrite Lock?
  12. State implementation of ReadWriteLock with different policies.

Interview Questions 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 refer to Object A, apart from that there is no live reference to either object A or B, Do they are eligible for Garbage collection?
  9. Does Garbage collection occur in permanent generation space in JVM?
  10. How can you control size ofPermGen 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 ask following questions based on GC output:

eg.

[GC

[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?

14. Should one Pool Object to help Garbage Collector? Should one call System.gc() periodically?

15. Why Java based GUI intensive program has Performance Issues?

16. There is a garbage collector alright, but then is memory leak totally absent in Java applications? If not, how so?

Interview Questions 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?

Interview Questions 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 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 it’s 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.

Interview Questions on Hibernate

  1. Why it's important to provide a default constructor in Java? What happens if your class don'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?

Interview Questions 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? Hmmm..is 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 prefer lists or arrays?
  10. What are the generally accepted naming conventions?
  11. How serialization works?
  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 contents leads to exceptions, how would one resolve it?
  23. How are dependent libraries packaged into an archive? Or Visibility of various classes in a bundled archive.
  24. How could a simple web service be provided?

Interview Questions on Spring

    1. What are types of IoC containers? Explain them.
    2. Why is dependency injection useful?
    3. Give an overview of how 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 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?

 

Interview Questions for Senior Java Developer:

  • What has been your experience with X, how did you use that?
  • What challenges you had with X and how did you overcome it?
  • Tell me some difficult problems you have solved and please tie that with the technologies you've listed on your resume.
  • Provide a hypothetical architecture arrangement, and ask for insights on design considerations.
  • 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 java Interview Questions for interview preparation. Read them, bookmark them, and even add your own interview questions in the comments below.

All The Best!

Rachana Mishra
Rachana Mishra
Growth Officer at Interview Mocha

Topics: Technical Hiring

Related Posts

Write for Interview Mocha

Editorial Guidelines:

Skills To Look For When Hiring For A Digital Marketer!

Remember the simpler times when marketing was all about ATL, BTL, and TTL? These acronyms mean above the line and below the line, through the line respectively. This basically means when you had to do the marketing of the products on big billboards, television, newspaper, and via flyers.