小厂面试经验(纯八股,包含答案)

1.LinkedList和ArrayList在数据量大的情况下哪个读取快

对于随机访问而言ArrayList更快,其底层是由动态数组实现,使用索引即可访问,时间复杂度为O(1),而LinkedList是由链表实现,要访问一个元素的时间复杂度为O(n);
对于全表扫描而言ArrayList更快,由于ArrayList是数组,其内存空间是连续的,于CPU而言,扫描内存是顺序的,对CPU缓存友好,所以访问时更快;而LinkedList每个值都是节点,内存未必是连续的,所以访问速度要逊于ArrayList;这两个的总体时间复杂度都为O(n)

2.单例模式
饿汉式,在加载之初就实例化对象,其线程安全但开销大

public class Singleton {
    private static Singleton instance = new Singleton();
    private Singleton (){}
    public static Singleton getInstance() {
        return instance;
    }
}

懒汉式,在需要时实例对象,线程不安全(安全可对getInstance方法加sychronized)

public class Singleton {
    private static Singleton instance;
    private Singleton (){}
    public static Singleton getInstance() {
        if (instance==null){
            instance=new Singleton();
        }
        return instance;
    }
}

双重锁,懒汉式,在需要时实例对象,线程安全且性能较高

public class Singleton {
    private static Singleton instance;
    private Singleton (){}
    public static Singleton getInstance() {
        if (instance==null){
            synchronized (Singleton.class){
                if (instance==null){
                    //这层判断为了多线程情况下,多个线程竞争锁从而导致多次实例对象
                    instance=new Singleton();
                }
            }
        }
        return instance;
    }
}

3.集合接口有哪些

List,Map,Set;在此可以延申出HashMap,ArrayList等

4.怎么设计数据库

数据库的范式

5.redis数据结构

string,list,hash,set,zset
redis数据结构

6.索引数据结构

b+ Tree为默认实现,除此之外还有哈希,空间,全文索引

7.索引失效场景

使用模糊匹配在左侧select * from user where name like '%王';
使用函数select * from user where length(name)=10;
使用表达式select * from user where id + 1 = 10;
隐式转换:字段为varchar类型而查询时用int,select * from user where name=123456相当于select * from user where cast(name as signed int) = 123456相当于用来函数;而当字段为int类型而查询时用var,select * from user where age ='1'其实相当于select * from user where age = ('1' as signed int)索引字段未使用函数所以索引仍旧生效
最左前缀法则:比如a,b,c为联合索引,如在条件不包含a那么会导致索引失效(如果包含a,那么顺序不重要,因为有查询优化器),如果条件为a=1 and c=1,在mysql5.5中没有索引下推,会先使用索引扫描符合a=1的数据,再全表扫描c=1的数据最后取交集;在mysql5.6之后使用索引下推,会先使用索引扫描符合a=1的数据,再在扫描到符合a=1的数据集中扫描c=1的数据;

8.隔离级别和带来的问题

读未提交:脏读
例子:a事务新增数据但未提交事务,b事务可查到a事务新增的数据
读已提交:可重复读
例子:b事务查询在a未提交事务时查不到数据,在a提交后查到数据
可重复读:幻读
例子:a事务删除id=1的数据并提交,而b事务可以查到id=1的数据但进行修改会出问题update name ='张三‘ where id =1

9.mysql有哪些锁

全局锁:主要应用于做全库逻辑备份
表级锁:对数据修改时会锁住整个表
行级锁:对数据修改时会锁住对应的行

10.快排

void quickSort(int[] arr, int left, int right) {
        if (right <= left) return;
        int l = left, r = right;
        int mid = arr[(l + r) / 2];
        while (l <= r) {
            while (arr[l] < mid) l++;
            while (arr[r] > mid) r--;
            if (l <= r) {
                int temp = arr[l];
                arr[l] = arr[r];
                arr[r] = temp;
                l++;
                r--;
            }
        }
        quickSort(arr, left, r);
        quickSort(arr, l, right);
    }

11.怎么部署java

springboot使用maven构建jar包,直接java -jar即可
ssm/ssh使用maven构建war包然后部署到tomcat服务器
在服务器可以使用 nohup进行挂载,也可用docker构建镜像然后部署

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值