数据类型

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

    • 整数类型

      • byte占1字节范围:-128~127

      • short占2个字节范围:-32768~32767

      • int占4个字节范围:-2147483648~2147483647

      • long占8个字节范围:-9223372036854775808~9223372036854775807

      • 整数扩展

        public class Demo03 {
           public static void main(String[] args){
               //整数拓展:   进制   二进制0b   十进制   八进制0   十六进制0x
               int i = 10;
               int i2 = 010;  //八进制0
               int i3 = 0X10; //十六进制0x   0~9 A~F

               System.out.println(i);
               System.out.println(i2);
               System.out.println(i3);
          }
        }
    • 浮点类型

      • float占4个字节

      • double占8个字节

      • 浮点扩展

        public class Demo03 {
           public static void main(String[] args){
               //浮点数拓展    
               //float
               //double

               float f = 0.1f; //0.1
               double e = 1.0/10; //0.1
               System.out.println(f);
               System.out.println(e);
               System.out.println(f==e); //false (不一样)

               //float   有限的   离散的   舍入误差   大约   接近但不等于

               float x1 = 123456789f;
               float x2 = x1 + 1;
               System.out.println(x1 == x2); //true (一样)
               //最好避免使用浮点数进行比较!
               //最好避免使用浮点数进行比较!
               //最好避免使用浮点数进行比较!
          }
        }

         

    • 字符类型

      • char占2个字节

      • 字符扩展

        public class Demo03 {
           public static void main(String[] args) {
               //字符拓展

               char a1 = 'a';
               char a2 = '瑭';
             
               System.out.println(a1);
               System.out.println((int)a1); //强制转换

               System.out.println(a2);
               System.out.println((int)a2); //强制转换

               //所有的字符本质还是数字
               //编码 Unicode 表:(a = 97 瑭 = 29825) 2字节 0 - 65536
               //注:所有的字符本质还是数字,编码Unicode表可以转译字符
               //U0000 UFFFF

               char a3 = '\u0061';

               System.out.println(a3); //a
          }
        }

  2. boolean类型:占1位其值只有true和false两个

 

引用类型(reference type)
  1. 接口

  2. 数组

转义符扩展
public class Demo03 {
   public static void main(String[] args) {
       //转义字符
       // \t 制表符
       // \n 换行

       System.out.println("中\t国");
       System.out.println("中\n国");
  }
}
上一篇:iOS 沙盒目录结构介绍


下一篇:使用PCL库将KITTI数据集可视化