Tuesday, February 12, 2008

Architect Questions

How do you ensure scalability in J2EE environment?


what version of hibernate have you used?

What parts of J2EE architecture do you recommend to avoid?

Friday, February 8, 2008

Interview Questions that were interesting...

Have you used Distributed Cache Product

http://www.oracle.com/products/middleware/coherence/index.html

The Leading Distributed In-Memory Data Grid Solution
Oracle Coherence is a component of Oracle Fusion Middleware that enables organizations to predictably scale mission-critical applications by providing fast and reliable access to frequently used data. By automatically and dynamically partitioning data in memory across multiple servers, Oracle Coherence enables continuous data availability and transactional integrity, even in the event of a server failure. As a shared infrastructure, Oracle Coherence combines data locality with local processing power to perform real-time data analysis, in-memory grid computations, and parallel transaction and event processing. Oracle Coherence comes in three editions. Find the edition that's right for you.

Announcing Oracle Coherence 3.3
Among many enhancements in the new release are improved performance, Quality-of-Service and clustering capabilities, and support for Microsoft's .NET Framework.

Do you know what a Covariant return type?

In J2SE 5 a method in a subclass may return an object whose type is a subclass of the type returned by the method with the same signature in the superclass. This feature removes the need for excessive type checking and casting.

More specifically, covariance of the return type refers to a situation where the return type of the overriding method is changed to a type related to (but different from) the return type of the original overridden method. The relationship between the two covariant return types is usually one which allows substitution of the one type with the other, following the Liskov substitution principle. This usually implies that the return types of the overridding methods will be subtypes of the return type of the overridden method. The above example specifically illustrates such a case.

http://en.wikipedia.org/wiki/Covariant_return_type

What is an anonymous class? What is it used for?

An anonymous class can be particularly useful in those cases where
There is no reason for an object of the anonymous class to exist in the absence of an object of the enclosing class.
There is no reason for an object of the anonymous class to exist outside a method of the enclosing class.
Methods of the object of the anonymous class need access to members of the object of the enclosing class.
Methods of the object of the anonymous class need access to final local variables and method parameters belonging to the method in which the anonymous class is defined.
Only one instance of the anonymous class is needed.
There is no need for the class to have a name that is accessible elsewhere in the program.

Write a bean class that utilizes generics in its syntax?

public class GenericsBean <T> {

private T t; // T stands for "Type"

public void set(T t) {
this.t = t;
}

public T get() {
return t;
}
}

Type Parameter Naming Conventions

E - Element (used extensively by the Java Collections Framework)
K - Key
N - Number
T - Type
V - Value
S,U,V etc. - 2nd, 3rd, 4th types


Hibernate version have you used?

EJB Version?

CDN experience content delivery networks

Easy Homework Assignment

Instructions

The following questions will help us assess your Java Programming skills. In all questions below, please make sure that the code you write is syntactically and semantically correct. Ideally, we should be able to compile and execute your code. Psuedo-code is not acceptable. Please read all instructions and directions before proceeding.

1. Is there a memory leak in the code below? If yes, can you spot the memory leak and fix the code to not leak?

public class Stack {
private Object[] elements;
private int size = 0;

public Stack(int initialCapacity) {
this.elements = new Object[initialCapacity];
}

public void push(Object e) {
ensureCapacity();
elements[size ++] = e;
}

public Object pop() {
if(size == 0)
throw new EmptyStackException();
return elements[--size];
}

public void ensureCapacity() {
if(elements.length == size) {
Object[] oldElements = elements;
elements = new Object[2 * elements.length + 1];
System.arraycopy(oldElements, 0, elements, 0, size);
}
}
}

If the stack grows and then shrinks, the objects will not be garbage collected that are being popped off the stack. The method should be re-written as:

public Object pop() {
If (size > 0) {
Object returnVal = elements[--size];
elements[size] = null;
return returnVal;
}
return null;
}


2. Write a class StringUtil that has a method reverseElements that accepts a String array and which returns the SAME String array with the array elements in reverse order. The signature of reverseElements should be

Void reverseElements(String[] strArr)


If strArr is { “dog”, “cat”, “mouse”, “cow” } before calling reverseElements, it should be {“cow”, “mouse”, “cat”, “dog”} after the call.

Using any other extra collection/array should also be avoided. We want you to manipulate the contents of the strArr itself.

public class StringUtil {
public StringUtil() { }

public void reverseElements(String[] strArr) {
int left, right;

for (left=0, right=strArr.length-1; left < right; left++, right--) {
String temp = strArr[left];
strArr[left] = strArr[right];
strArr[right] = temp;
}
}
}

3. Write a unit test for StringUtil#reverseElements.

public void testReverseElements() {
String myStrArr[] = { "dog", "cat", "mouse", "cow" };
StringUtil mySU = new StringUtil();
mySU.reverseElements(myStrArr);
assertEquals("cow", myStrArr[0]);
assertEquals("mouse", myStrArr[1]);
assertEquals("cat", myStrArr[2]);
assertEquals("dog", myStrArr[3]);
}


4. Define class Foo such that there can at any time be exactly one instance of Foo.

public class Foo {
private static Foo myInstance;

private Foo() { }

public static Foo getInstance() {
if (myInstance == null)
myInstance = new Foo();

return myInstance;
}
}


5. class Bar {
private String _name;
private int _age;

Bar(String inName, int inAge) {
_name = inName;
_age = inAge;
}
}

Identify the base class of Bar. Bar is its own base class
Determine the method signature of equals in Bar’s base class equals(String, int)
Override and re-implement it such that the equals method returns true only if name and age match. In other words we want to be able to compare two Bar instances.

class FooBar extends Bar {
FooBar(String inName, int inAge) {
super(inName, inAge);
}

@Override
public boolean equals(String inName, int inAge) {
return super.equals(inName, inAge);
}
}


6. In the question above, if you override the equals method, is there any other method of class Object that needs to be overridden? If so, which one?

It is a general rule that if you override the equals() method you always override the hashCode() method also.