Top java interview questions

We share some most frequently and important java interview questions.

Not only are these questions frequently asked by interviewers, but also

that they are essential for you to master core Java.

  1. How do you implement your own Key Object for HashMap?

    To answer such as question, you probably should also get familiar with the concept of HashTable. Since HashTable use a hash function to map an object to the index of the underlying Array, you need to implement the hashcode method. As there can be conflicts: Two object generate the same hashcode, we also need to implement the equal function to ultimately determine whether two objects are the same based on the business rules.

  2. The difference between StringBuilder and StringBuffer in Java

    The difference between HashMap and HashTable in Java
    They are similar questions. Both StringBuffer and HashTable are synchronized, while both StringBuilder and HashMap are not synchronized.  So, StringBuilder and HashMap are faster but they are not thread safe.

    Similar questions:

    The difference between ArrayList and Vector

  3. What is Singleton? How do you implement it?

    The concept of Singleton is simple. It is the easiest design pattern. It means there is only one instance (object) or a class in the application.

    There are many methods to implement a Singleton pattern. To answer this question correct, you must make it Thread safe and Fast.

  4. What are difference between Abstract and Interface in Java?

    A simple answer can be:

    Both must be subclassed to create instance.

    Abstract can contain non abstact method, but Interface contains only abstact method.

    If a sub class extends an abstract class, it can not extends other abstract class anymore, but a sub class can implement many interfaces.

    See two articles that have a detailed discussion:

    Abstract class:

    Interface in Java:

Recommend Book to Learn Java:

  1. Head First Java
  2. Head First Object-Oriented Analysis and Design
  3. Effective Java