JAVA面试题

一 什么基础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的删除增加需要指针移动

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值