数据类型与面试题

数据类型与面试题

1. 基本数据类型(primitive type)

  1. 整数类型:byte、short、int、lone

    • 拓展(进制)
      • 二进制:0b
      • 八进制:0
      • 十进制
      • 十六进制:0x
  2. 浮点型:float、double

    • 拓展:
      • 最好完全避免用浮点数进行比较!!!
      • 银行业务怎么表示?钱
        • BigDecima 数字工具类
  3. boolean型:true、false

    • 拓展

      boolean flag = true;
      if(flag == true) {}// 新手
      if(flag) {}// 老手
      
  4. 字符型:char

    • 拓展:

      • 所有的字符本质还是数字(unicode表)

        char c1 = 'A';
        System.out.println((int)c1);// 65,强制转换
        char c2 = '\u0061';
        System.out.println(c2);// a
        
      • 转义字符

        • \t:制表符
        • \n:换行
  5. 拓展

    String a = new String("hello");
    String b = new String("hello");
    System.out.println(a==b);// false
    
    String c = "hello";
    String d = "hello";
    System.out.println(c==d);// true
    

2.引用数据类型(reference type)

  1. 接口
  2. 数组

3.类型转换

注意点:

  1. 不能对布尔值进行转换
  2. 不能把对象类型转换为不相干类型
  3. 高容量转换为低容量,强制类型转换
  4. 转换时可能存在内存溢出或精度问题
posted @ 2021-11-02 11:24  lohir  阅读(48)  评论(0)    收藏  举报