2020 java 面试专题记录

2020-08-21  本文已影响0人  痴痴爱码字

面试专题

Java体系

stream流


lambda和接口

接口的默认方法 :

public interface Animal {
    default void fly() {
        System.out.println("birds can fly...");
    }

    default void swim() {
        System.out.println("fishes can swim......");
    }
}

public class Bird implements Animal {
}

public class TestMain {

    public static void main(String[] args) {

        Bird bird = new Bird();
        bird.fly();

        Fish fish = new Fishe();
        fish.swim();
    }
}

接口的静态方法 :

public interface AnimalFactory {

    static Animal create(Supplier<Animal> supplier) {
        return supplier.get();
    }
}

public class TestAnimalFactory {

    public static void main(String[] args) {
        // 生产一只鸟
        Animal bird = AnimalFactory.create(Bird::new);
        bird.fly();
     // 生产一条鱼
        Animal fish = AnimalFactory.create(Fishe::new);
        fish.swim();
    }
}

函数式接口

@FunctionalInterface
interface GreetingService 
{
    void sayMessage(String message);
}

Lambda 表达式

// 1. 不需要参数,返回值为 5  
() -> 5  
  
// 2. 接收一个参数(数字类型),返回其2倍的值  
x -> 2 * x  
  
// 3. 接受2个参数(数字),并返回他们的差值  
(x, y) -> x – y  
  
// 4. 接收2个int型整数,返回他们的和  
(int x, int y) -> x + y  
  
// 5. 接受一个 string 对象,并在控制台打印,不返回任何值(看起来像是返回void)  
(String s) -> System.out.print(s)
public class Java8Tester {
   public static void main(String args[]){
      Java8Tester tester = new Java8Tester();
        
      // 类型声明
      MathOperation addition = (int a, int b) -> a + b;
        
      // 不用类型声明
      MathOperation subtraction = (a, b) -> a - b;
        
      // 大括号中的返回语句
      MathOperation multiplication = (int a, int b) -> { return a * b; };
        
      // 没有大括号及返回语句
      MathOperation division = (int a, int b) -> a / b;
        
      System.out.println("10 + 5 = " + tester.operate(10, 5, addition));
      System.out.println("10 - 5 = " + tester.operate(10, 5, subtraction));
      System.out.println("10 x 5 = " + tester.operate(10, 5, multiplication));
      System.out.println("10 / 5 = " + tester.operate(10, 5, division));
        
      // 不用括号
      GreetingService greetService1 = message ->
      System.out.println("Hello " + message);
        
      // 用括号
      GreetingService greetService2 = (message) ->
      System.out.println("Hello " + message);
        
      greetService1.sayMessage("Runoob");
      greetService2.sayMessage("Google");
   }
    
   interface MathOperation {
      int operation(int a, int b);
   }
    
   interface GreetingService {
      void sayMessage(String message);
   }
    
   private int operate(int a, int b, MathOperation mathOperation){
      return mathOperation.operation(a, b);
   }
}

执行结果:
$ javac Java8Tester.java 
$ java Java8Tester
10 + 5 = 15
10 - 5 = 5
10 x 5 = 50
10 / 5 = 2
Hello Runoob
Hello Google

Lambda 作用域 :

lambda 表达式只能引用标记了 final 的外层局部变量,这就是说不能在 lambda 内部修改定义在域外的局部变量,否则会编译错误。


springboot 框架

springboot 1.x 和 2.x 的区别

Spring Boot @RestController和@controller有什么区别?

Spring Boot 的配置文件有哪几种格式?它们有什么区别?

Spring Boot 自动配置原理是什么?

Spring Boot 有哪几种读取配置的方式?


Mybatis 框架

#{}和${}的区别是什么?

当实体类中的属性名和表中的字段名不一样 ,怎么办 ?

模糊查询like语句该怎么写?

如何执行批量插入?

如何获取自动生成的(主)键值?

在mapper中如何传递多个参数?

接口绑定有几种实现方式,分别是怎么实现的?


Mysql

mysql优化

    select id from t where num=10 or Name = 'admin'
    #可以这样查询:
    select id from t where num = 10
    union all
    select id from t where Name = 'admin'

redis

常用数据类型

Redis应用场景,能做什么

  1. 数据缓存(最常用)
  2. 会话session管理器(最常用)
  3. 消息队列(支付)
  4. 活动排行榜或计数
  5. 发布,订阅消息(消息通知)
  6. 商品列表,评论列表

缓存穿透

缓存击穿

缓存雪崩

布隆过滤器

Memcache与Redis的区别都有哪些?

单线程的redis为什么这么快

如果redis没有设置expire,他是否默认永不过期?

Redis 部署方式

分布式锁

Redis的持久化

Redis 发布订阅


linux

常用命令

查看端口

netstat命令各个参数说明如下:
-t : 指明显示TCP端口 
-a : 显示所有的套接字
-u : 指明显示UDP端口 
-l : 仅显示监听套接字(所谓套接字就是使应用程序能够读写与收发通讯协议(protocol)与资料的程序) 
-p : 显示进程标识符和程序名称,每一个套接字/端口都属于一个程序。 
-n : 不进行DNS轮询,显示IP(可以加速操作) 
上一篇 下一篇

猜你喜欢

热点阅读