一 什么基础IO是什么时候关闭的
答:关闭的模式有三种
1 在finaly中关闭
OutputStream out = null; try { out = new FileOutputStream(""); // ...操作流代码 } catch (Exception e) { e.printStackTrace(); } finally { try { if (out != null) { out.close(); } } catch (Exception e) { e.printStackTrace(); } }
2 在try中做判断关闭,并捕捉异常
OutputStream out = null; OutputStream out2 = null; try { out = new FileOutputStream(""); out2 = new FileOutputStream(""); // ...操作流代码 } catch (Exception e) { e.printStackTrace(); } finally { try { if (out != null) { out.close();// 如果此处出现异常,则out2流也会被关闭 } } catch (Exception e) { e.printStackTrace(); } try { if (out2 != null) { out2.close(); } } catch (Exception e) { e.printStackTrace(); } }
3 在流的外循环中关闭
for (int i = 0; i < 10; i++) { OutputStream out = null; try { out = new FileOutputStream(""); // ...操作流代码 } catch (Exception e) { e.printStackTrace(); } finally { try { if (out != null) { out.close(); } } catch (Exception e) { e.printStackTrace(); } } }
4 通过工具类关闭
二 什么数据库事务及数据库事务的概念
数据事务有四个特性:
1 原子性:数据库的事务操作要么全部完成,要么全部不执行
2 一致性:几个并行执行的事务,其执行结果必须与按某一顺序 串行执行的结果相一致
3 隔离性:事务的执行不受其他事务的干扰,事务执行的中间结果对其他事务必须是透明的
4 持久性:对于任意已提交事务,系统必须保证该事务对数据库的改变不被丢失,即使数据库出现故障
三 ArrayList与LinkedList的区别
相同点:都是非同步线程,不安全的线程
不同点:
1 LinkedList是基于链表的数据结构,而ArrayList是基于动态数组的数据结构
2 ArrayList的访问要优于LinkedList,因为LinkedList数据结构是基于链表的,所以在访问数据的时候,时间复杂度是O(n),而ArrayList是动态数组结构所以在访问的时候是O(1)
3 LinkedList的删除和增加优于ArrayList,因为ArrayList的删除增加需要指针移动