java数据类型
基本数据类型:
- 整型:byte,short,int,long
- 浮点类型:float,double
- char类型:char
- 布尔类型:boolean
引用数据类型:
- 类:class
- 接口:interface
- 数组:[]
整型特征:
- byte:1字节
- short:2字节
- int:4字节
- long:8字节,后缀为L或l
- 16进制:0x或0X , 8进制:0 ,2进制:0b或0B
浮点类型特征:
- float:单精度,后缀F或f
- double:双精度,后缀D或d
char类型:
- ’ ':代表字符常量,eg:'A’表示编码值为65的字符常量
- " ":代表字符串,eg:"A"表示一个字符A的字符串
数值类型之间转换
- int转换为float,long转换为float,long转换为double:可能发生精度损失的情况
数组
- 数组声明:int[] number = new int[100]或int[] number = {20,30,50}
- 匿名数组:new int[] {20,30,50}
- 多维数组:int[][] numbers = new int[2][2]或int[][] numbers = { {13,12},{20,30}}
类
- 类对象声明:Date date = new Date()
- 对象变量的引用并没有实际包含一个对象,它只是应用一个对象