Tuesday, December 6, 2011

Program to produce OutOfMemoryError in Java

The below program produced the 'java.lang.OutOfMemoryError' in couple of seconds when i ran in my machine. :-)

public class OutOfMemory {
static int count = 0;
static ArrayList aString = new ArrayList();
static String string;
public static void main(String[] args) {
while (true){
int i=0;
string = new String("Achyuth");
aString.add(string);
aString.addAll(aString);
System.out.println(count++ +" "+aString.size());
}
}
}

Sunday, November 13, 2011

Java
  1. What is Deep cloning and Shallow cloning. If we clone a HashMap will it clone all the Objects it is holding or have the reference to the same Objects.
  2. You serialize an object and passed it to another JVM. Before deserializing, how do you check whether the same object is already present in the JVM.
  3. How to Sort an employee object, Tree map.
  4. How to make immutable employee object. This employee object has a phone object used. How to ensure that the phone object is also immutable.
  5. How to create a map with two key and one values.

Tuesday, May 3, 2011