1.基本数据类型
byte,short,int,long,char,float,double,boolean
type | lenth(Byte) | 初始值 |
byte | 1 | 0 |
short | 2 | 0 |
int | 4 | 0 |
long | 8 | 0L |
char | 2 | ‘\u0000’ |
float | 4 | 0.0f |
double | 8 | 0.0 |
boolen | 4或1 | false |
boolean的长度没有明确定论,组成数组时boolean占1Byte,单独定义时占4个Byte
2.类型转换
2.1自动转换
-容量小的类型可以自动转换为容量大的类型
-byte,short,char之间不会自动转换,需要先转化成int类型
-基本类型和字符串进行“+”运算时会将基本类型转换为字符串类型
2.2强制转换
-强制转换可以将容量大的类型转换为容量小的类型,但可能产生精度降低或溢出