----

Java Interview Questions

Top Java Interview Questions for Experienced Programmer

Following are the most popular java concepts questions which are frequently asked by interviewers:
So get hired by simply answering these important Questions.

Question: What are basic OOPS concepts (Class, Object, Inheritance, Polymorphism, Abstraction and Encapsulation)?

Question: What is difference between abstract class and interface explain with example?

Question: Why multiple inheritance is not supported in java?

Question: What are the methods defined in the Object class?

Question: What is the difference between String s1="idris" and String s2 = new String("idris")? where s1 and s2 will be created? (Hint: in String pool and on heap memory)

Question: How to create immutable Object ? or How to make an object immutable?

Question: How to make an object immutable if it contains an other object (as class field or reference) who's state can be changed?

Question: What is the difference between NoClassDefFoundError and ClassNotFoundException?

Question: What are different ways to create a Thread?

Question: When to use Runnable to create a Thread?

Question: How to create deadlock using Threads? Hint: 1. Using Object locks, 2. Using thread.join().

Question: What is Daemon Thread and how to create it?

Question: How Threads share data with each other?

Question: Why sleep and yield methods are static?

Question: How wait and notify methods works? How locking works for synchronization?

Question: Write a program to print 1 2 3 4....100 using threads where one thread is producing even numbers and other thread producing odd numbers.

Question: Write a program where multiple producers and consumers threads are involved.

Question: How to detect deadlock in a java application? (Hint: JConsole, JVisualVM etc)

Question: What is an iterator? write a program to implement an iterator.

Question: What are the differences between ListIterator and iterator? Can we iterate backwards using iterator?

Question: Why java has two different implementation of List interface (LinkedList and ArrayList)?

Question: What are the differences between LinkedList and ArrayList? Which one is best in which situations? Hint: In term of Memory usage , access of elements , addition and removal of elements.

Question: Say List list = new ArrayList(4)  now add  1 ,2 ,3 ,4  to it, How or when this list will grow by its size? How can we create an ArrayList of a constant size say 4? it should not grow or accept any more values on insert.

Question: What are the differences between comparable and comparator?

Question: What dose finally block do, is it always guaranteed  to execute?

Question: What is resource bundle. why we use it?

Question: How to read a file from resource?

Question: What is marker interface? why we need it or what is the use of it?

Question: How serialization happens only by using serializable interface? who does it? even if we are not writing any method for serialization in the class which is implementing serializable interface.

Question: Why we do not override the read and write object methods and if we do then what will happen during serialization?

Question: If we have any static filed in class then how it will be serialized ?

Question: Is it possible to get the Object which is serialized using new version of java 1.7 and de-serialize using the old version of java 1.4 or vice versa?

Question: What will happen if we serialize an object having only one method and we change the class/ object by adding or removing one or more methods to it, now we de-serialize it?

Question: Two classes where B extends A (A is parent of B), What will happen if we implement serializable only in B and try to serialize B?

Question: In above if we deserialize B, whether the constructor of A or B will be invoked or not?

Question: Can we serialize Singleton class? if Yes then how to avoid creation of duplicate object of Singleton class?

Question: How to increase heap size in java, what is the way to increase heap size?

Question: How garbage collector works? What are the algorithms used for garbage collection?

Question: What are generations in jvm, explain the purpose  of young generation, old generation and permanent generation in jvm?

Question: How Objects are passed in methods, pass by reference or pass by value?

Question: Where we can access protected methods and fields , can we access them within the same package?

Question: What is the difference between HashSet and TreeSet, which one is faster?

Question: How TreeMap works, which kind of Object we can put in it? Hint: How it Sorts objects using Comparable and Comparator.

Question: What is best data structure to store Telephone directory? Hint: TreeMap, BidiMap, MultiMap.

Question: What is generic and how to use it in collections?

Question: What is Bounded and Unbounded wild-cards in Generics ?

Question: How to print "Hello world" without invoking main method?

Question: What is concurrency and what concurrent map? Why we need a concurrent map?

Question: What is un-modifiable collection and map?

Question: What is fail fast and Fail safe? when ConcurrentModificationException will be thrown and why?

Question: What is static import? if we have same static method in two classes and if we do a static import what will happen, will be there any ambiguity for methods?

Question: Why instance-of check is costly(slow)?

Question: If the hash code is same for two object then how they will be located in HashSet or Map?

Question: What are the best practice to use collections?

Question: How a HashMap works?  Hint: based on hash code

Question: What are best practices to override the equals and hash code?

Question: What will be the impact if I override only hash code? or if I return same hash code for all?

Question: What are best practices to create Key or use an object as Key in hashMap?

Question: If we override the equals method but not hash code for a class A, and use this class in HashMap as a key, Now if i say map.get(new A()); what will be the output and why?

Question: What are annotations? how to write custom annotation and how to detect and invoke the user defined annotations?

Question: What is ExecutorService? How Executor framework works? Hint: Thread-Pool

Question: Write a program to insert and delete a node from binary tree?

Question: Write an algorithm to print nodes values at each level (BFS)?

Question: Write an algorithm to find the smallest node in binary tree (DFS)?

Question: What is Atomic in java?

Question: Why count++ or ++count is not Atomic operation? if int count=0.

Question: What operations in Java are considered atomic?
Hint:
    • all assignments of primitive types except for long and double
    • all assignments of references
    • all operations of java.concurrent.Atomic* classes
Question: What kind of caching mechanism/techniques have you used? How to implement them?

Question: What is Least Recently Used (LRU cache) algorithm, How to implement it?

Question: Write a program to add and remove an element from Linked list. Hint: Using slow and fast indexs or pointers.

Question: Implement a Queue, Priority Queue using Linked list.

Question: How to find middle element of a Linked list in one pass (iteration)?

Question: How merge and quick sort works?

Question: How to sort an array of integer using only one iteration?

Question: How to implement a stack which can give me the smallest element present in the stack at any point (when we need or call getMin())? we can do push and pop any time and can get min also.(Hint: A custom Stack class which can have 2 stack in it, s1 will have actual values and s2 will store min values)

Question: How to calculate complexity (Big O) of an algorithm other than brute force algorithm?

Question: What is association, aggregation and composition explain with examples?

Question: How load balancing works in web servers, how to do load balancing (algorithm implementation)?

Read More Java Questions with Ans...

3 comments :

  1. Is there a list of answers to compliment the list of questions?

    ReplyDelete
  2. Would be nice to get answers to these! :)

    ReplyDelete