Q:請大概描述一下Vector和ArrayList的區(qū)別,Hashtable和HashMap的區(qū)別。(5)
A:thread-safe or unsafe, could contain null values or not
Q:請問你在什么情況下會在你的JAVA代碼中使用可序列化?(5)
為什么放到HttpSession中的對象必須要是可序列化的?(5)
A:save, communicate
Q:為什么在重寫了equals()方法之后也必須重寫hashCode()方法?(10)
A:implementations of dictionaries need hashCode() and equals()
Q:Sleep()和wait()有什么區(qū)別?(10)
A:threads communication: wait() and notifyAll()
sleep hold lock and wait auto release lock.
Q:編程題:用最有效率的方法算出2乘以17等于多少?(5)
A: 2<<4+2
Q:JAVA是不是沒有內(nèi)存泄漏問題?看下面的代碼片段,并指出這些代碼隱藏的問題。(10)
…
Object[] elements = new Object[10];
int size;
…
public Object pop() {
if (size == 0)
return null;
Object o = elements[--size];
return o;
}
A: elements[size] = null;
Q:請闡述一下你對JAVA多線程中“鎖”的概念的理解。(10)
A:optimistic lock, pessimistic lock, signal, dead lock, starvation, synchronization
Q:所有的遞歸實現(xiàn)都可以用循環(huán)的方式實現(xiàn),請描述一下這兩種實現(xiàn)方式各自的優(yōu)劣。
并舉例說明在什么情況下可以使用遞歸,而在什么情況下只能使用循環(huán)而不能使用遞歸?(5)
A:recursive: when you need a stack and stack memory is enough
non-recursive: when you need a queue
Q:請簡要講一下你對測試驅(qū)動開發(fā)(TDD)的認(rèn)識。(10)
A:write unit testing code first
Q:請闡述一下你對“面向接口編程”的理解。(10)
A:adapter, listener, bridge, decorator, proxy… patterns
Q:在J2EE中有一個“容器(Container)”的概念,不管是EJB、PICO還是Spring都有他們
各自實現(xiàn)的容器,受容器管理的組件會具有有生命周期的特性,請問,為什么需要容器?
它的好處在哪里?它會帶來什么樣的問題?(15)
A:encapsulation decouple.
Q:請闡述一下你對IOC(Inversion of Control)的理解。(可以以PICO和Spring的IOC作為例子說明他們在實現(xiàn)上各自的特點)(10)
A:reduce classes' dependencies
Q:下面的代碼在絕大部分時間內(nèi)都運行得很正常,請問在什么情況下會出現(xiàn)問題?問題的根源在哪里?(10)
import java.util.LinkedList;
public class Stack {
LinkedList list = new LinkedList();
public synchronized void push(Object x) {
synchronized(list) {
list.addLast( x );
notify();
}
}
public synchronized Object pop()
throws Exception {
synchronized(list) {
if( list.size() <= 0 ) {
wait();
}
return list.removeLast();
}
}
}
A: dead lock, synchronized on both 'list' and 'this'