java面试题及答案(基础题122道,代码题19道) (1)

匿名网友 匿名网友 发布于: 2015-08-30 00:00:00
阅读 158 收藏 0 点赞 0 评论 0

1。请大概描述一下Vector和ArrayList的区别,Hashtable和HashMap的区别。(5)

// thread-safe or unsafe, could contain null values or not

2。请问你在什么情况下会在你的JAVA代码中使用可序列化?(5)
为什么放到HttpSession中的对象必须要是可序列化的?(5)

// save, communicate

3。为什么在重写了equals()方法之后也必须重写hashCode()方法?(10)

// implementations of dictionaries need hashCode() and equals()

4。sleep()和wait()有什么区别?(10)

// threads communication: wait() and notifyAll()

5。编程题:用最有效率的方法算出2乘以17等于多少?(5)

// 2<<4+2

6。JAVA是不是没有内存泄漏问题?看下面的代码片段,并指出这些代码隐藏的问题。(10)

Object[] elements = new Object[10];
int size;

public Object pop() {
if (size == 0)
return null;
Object o = elements[–size];
return o;
}

// elements[size] = null;

7。请阐述一下你对JAVA多线程中“锁”的概念的理解。(10)

// optimistic lock, pessimistic lock, signal, dead lock, starvation, synchronization

8。所有的递归实现都可以用循环的方式实现,请描述一下这两种实现方式各自的优劣。
并举例说明在什么情况下可以使用递归,而在什么情况下只能使用循环而不能使用递归?(5)

// recursive: when you need a stack and stack memory is enough
// non-recursive: when you need a queue

9。请简要讲一下你对测试驱动开发(TDD)的认识。(10)

// write unit testing code first

10。请阐述一下你对“面向接口编程”的理解。(10)

// adapter, listener, bridge, decorator, proxy… patterns

11。在J2EE中有一个“容器(Container)”的概念,不管是EJB、PICO还是Spring都有他们
各自实现的容器,受容器管理的组件会具有有生命周期的特性,请问,为什么需要容器?
它的好处在哪里?它会带来什么样的问题?(15)

// encapsulation

12。请阐述一下你对IOC(Inversion of Control)的理解。(可以以PICO和Spring的IOC作为例子说明他们在实现上各自的特点)(10)

// reduce classes’ dependencies

13。下面的代码在绝大部分时间内都运行得很正常,请问在什么情况下会出现问题?问题的根源在哪里?(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();
}
}
}

// dead lock, synchronized on both ‘list’ and ‘this’

评论列表
文章目录