java面试总结
1,java集合的框架结构
https://www.cnblogs.com/paddix/p/5539326.html
至于Vector,它是ArrayList的线程安全版本
与之前提到的HashSet与TreeSet的区别是一致的,在后续进行源码分析的时候,我们可以看到HashSet和TreeSet本质上分别是通过HashMap和TreeMap来实现的,所以它们的区别自然也是相同的。HashTable现在已经很少使用了,与HashMap的主要区别是HashTable是线程安全的,不过由于其效率比较低,所以通常使用HashMap,在多线程环境下,通常用CurrentHashMap来代替。
2,实现多线程的三种方式
http://www.cnblogs.com/felixzh/p/6036074.html
(1)继承Thread
(2)实现Runnable接口
(3)实现Callable接口
只有Callable接口可以接收线程的返回值,其他的都不可以
/**
* 使用ExecutorService、Callable、Future实现有返回结果的线程
* @author 1
*
*/
public class ThreadTest {
public static void main(String[] args) throws InterruptedException, ExecutionException {
int poolSize = 5;
//创建一个线程池
ExecutorService threadPool = Executors.newFixedThreadPool(poolSize);
//创建一个可以接收结果的list
List<Future> futureList = new ArrayList<Future>();
for(int i = 0; i < 5 ; i ++) {
Callable<String> callable = new MyCallable("Thread" + i);
Future<String> future = threadPool.submit(callable);
futureList.add(future);
}
// 关闭线程池
threadPool.shutdown();
System.out.println("------------------------------------------");
// 获取所有并发任务的运行结果
for (Future f : futureList) {
// 从Future对象上获取任务的返回值,并输出到控制台
System.out.println(">>>" + f.get().toString());
}
}
}
class MyCallable implements Callable<String>{
private String name;
public MyCallable(String name){
this.name = name;
}
@Override
public String call() throws Exception {
System.out.println(">>>" + name + "任务启动");
Date dateTmp1 = new Date();
Thread.sleep(1000);
Date dateTmp2 = new Date();
long time = dateTmp2.getTime() - dateTmp1.getTime();
System.out.println(">>>" + name + "任务终止");
return name + "任务返回运行结果,当前任务时间【" + time + "毫秒】";
}
}
3,java io流的框架
https://www.cnblogs.com/yyy-blog/p/7003693.html