1. Write class for the tree structure and method to calculate cummulative sum.
2. What are the rules for Recursion and its drawback ?
3. Suppose I have 10GB text file having numeric values (one per line), on 64 bit JVM with Linux OS, 2 GB RAM and 240 GB Hard disk.
What is most efficient way to find largest number and 10th largest number ?
Can PriorityQueue be a efficient data structure over array of 10 elements, while finding 10th largest number ?
4. Why methods notify(), wait() are provided in Object class not in thread class ?
Written test
1. A class person is given. Person A treated to be greater than Person B, if age of Person A is more than Person B.
If age is same, then natural sorting of name should be used.
Implement standard 2 methods from collection API to sort person list.
public class Person {
private String name;
private int age;
Person(String name, int age) {
this.name = name;
this.age = age;
}
2. What would be the expected output / error / exception and if any error / exception, how to fix it ?
public class IteratorDemo {
public static void main(String[] args) {
List list = new ArrayList();
list.add("XYZ1");
list.add("XYZ2");
list.add("XYZ3");
list.add("XYZ4");
Iterator iterator = list.iterator();
for (int index = 0; iterator.hasNext(); index++) {
String next = iterator.next();
if(next.equals("XYZ2"))
list.remove(index);
}
}
}
3. Write memory implementation of "AgedCache" as per following interface which "evicts" data that is older than a specified period (5 mins.). Cache should remove keys and data which is older than specified period.
public interface Cache {
void put(Object key, Object value);
Object get(Object key);
}
Synchronization should be used.
4. Using java 1.4 or below, without third party lib, implement following interface specification for object pool.
public interface Pool {
Object unpool();
void pool(Object o);
int available();
int allocated();
int max();
}
Object pool should be client configured with max number of objects that it manages.
5. Describe when this code will be executed, whether it completes or not ? Give proper reasoning.
Note: Stack depth is not unlimited.
public class Recursion {
public static void main(String[] args) {
try {
recurse();
}
finally {
System.out.println("hi");
}
}
static void recurse() {
try{
recurse();
}
finally{
recurse();
}
}
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.