1. 基本数据类型(Premitive Type)
1) 数值类型
i.整数类型
byte: 8 bit 1个字节 -128 ~127
short : 16bit 2个字节
int: 32bit 4个字节
long:64bit 8个字节
具体数值是多少其实不用记,如果太长了超过了限制,IDEA会帮你报错的。真的要查,可以查类型相对应的类,里面定义了最大值和最小值
long a = 30L;// L or l is a must for indicating this is a long type number
注意:小写的l容易看不清, 会和1或者大写字母I混合,所以其实我们一般用大写的L。
ii. 浮点类型
float: 4个字节
double : 8个字节
float b = 1.23f; //f is must for indicating that this is a float type number
double d = 1.23;
iii. 字符类型
char: 2个字节
一个汉字就占一个char, 如果这样定义,IDEA会帮你报错的:
应该这样定义:
char a = '中';
2)布尔类型
boolean, 占1位 0 /1
boolean flag1 = true;
boolean flag2 = false;
2. 引用数据类型 (Reference Type)
除了基本数据类型的都是引用数据类型:
数组、类、接口
3. More
1 G = 1024 M
1 M = 1024 KB
1 KB = 1024 B (Byte)
1 B = 8 b (bit)