Java language must run similarly on any hardware/operating-system platform

Java Interview Questions

Morgan Stanley:

1. How to create a thread safe Array List which can be modifiable ?
2. How to optimize the message Queue or to handle more number of messages by the Consumer ?
Example: we need to think optimized way of consuming the Message queue so that Message queue will not get full.
3. How to get the list of files with descending order for the given Drive in the file system?
Example : The file name should be ordered by the file size. The driver will have N Directory.


Design a stack such that getMinimum( ) should be O(1)

Amazon Interview Questions

Data structure:
The data structure is used to store some data in memory
• Arrays
• Linked List
• Tree: Binary tree, Binary search tree, Red–black tree
• Heap
• Hash table
• Stack,
• Queue
• Graph: Both Directed and Undirected graph

How to process the data like sort , quickly fetch data from the data structure
• Merge sort
• Quick sort
• Radix sort

Java interview question part 2

1. Singleton class: I was asked everything about it. To code the entire class and then cross questions on usage of every keyword.

Link to prepare:

2. Hashing algorithm and how hash map works in detail.

3. String creation in heap & string pool.

4. Entire collection framework with scenarios when to use what & why?

5. Basics of multithreading concepts.

6. Functional Interface (I could not answer, I guess this is made available in Java 8).

7. Few performance issue related questions.

Inteview question on Threading

1.How to make List immutable in java?
The Collection has method unmodifiableList will returns the list Immutable.
The returned unmodifiableList wont support add , remove , alteration operation ,
If add, remove, alteration is done then UnsupportedOperationException Exception is thown.
List list1 = Collections.unmodifiableList(list);

What is the difference between wait state & sleep state?
What is the use of the thread yield method ?
what is future objects in Java ?

What is Daemon Thread differs from Normal Thread?

How to avoid the Concurrent exception

The cause of the exception is modifying the list after iterator is created, Hence we should do operation in list before the iterator is created means calling remove before iterator call .

List<Integer>  tmp = new ArrayList<Integer>(0); 
		Iterator<Integer> it =  tmp.iterator();
		System.out.println(" Exception will be fired here " +;    

Core Java Interview questions

In java why Object class needs to be inherited by default?
For polymorphism we need a common one base class (Object class) should be available to receive any user custom class
Example: The println method public void println(Object x) { }
System.out.println(new student());

•In java when class will implicitly inherit Object class ?
Answer: when a class does not extends base class then Object class will be extended

•what is weak references and strong references ?
Strong reference : Not eligible for garbage collection

Difference between String, StringBuffer, StringBuilder

String object is immutable means for each update operation internally java creates new object.
StringBuffer/StringBuilder objects are mutable means updating values are more efficient hence increase performance.
StringBuffer is synchronized means it is thread safe
StringBuilder is not synchronized hence carefull in using multi thread environment
Mostly all page controller will have common method for execution Hence carefull in using global variable.