How do you get an Immutable Collection

This functionality is provided by the Collections class, which is a wrapper implementation using the decorator design pattern. public class ReadOnlyExample { public static void main(String args[ ]) { Set<string> set = new HashSet<string>( ); set.add(“Java”); set.add(“JEE”); set.add(“Spring”); set.add(“Hibernate”); set = Collections.unmodifiableSet(set); set.add(“Ajax”);                                           // not allowed. } } In Java, to create an immutable collection, … Read more

What is the Tradeoff Between using an Unordered array Versus an ordered array

The major advantage of an ordered array is that the search times are much faster with O (log n) than an unordered array, which is O (n) for larger values of n. The disadvantage of an ordered array is that the insertion takes longer (i.e. O (n) ) because all the data with higher values … Read more

What do you know About the big-O notation and can you give some Examples with Respect to Different Data Structures

The Big-O notation simply describes how well an algorithm scales or performs in the worst case scenario as the number of elements in a data structure increases.  The Big-O notation can also be used to describe other behavior such as memory consumption. At times you may need to choose a slower algorithm because it also … Read more

What are the Common Data Structures, and where would you use them? How you would go about Implementing your own List, Set, and Map

Many leave out Trees and Graphs. Trees and Graphs are very useful data structures as well.Whilst it is not recommended to write your own implementation when Java provides proven and tested implementations, the interviewer is testing your understanding on data structures. My book entitled “Core Java Career Essentials” covers this in more detail with diagrams, … Read more

What Changes are Compatible and Incompatible to the Mechanism of Java Serialization

This is one of a difficult and tricky questions and answering this correctly would mean you are an expert in Java Serialization concept. In an already serialized object, the most challenging task is to change the structure of a class when a new field is added or removed. As per the specifications of Java Serialization, … Read more