//基本数据类型分类
public class Test03{
public static void main(String[] args) {
//整数根据取值范围又分为四种数据类型,从小到大依次是byte->short->int->long java中默认整数为int类型
//byte取值范围-128~127
byte a=-128,b=127;
//此处只能a+b不能(a,b)?! 可能是底层没有设定过这样的方法
![byte,byte报错](https://img-blog.csdnimg.cn/2019110322185651.jpg)
System.out.println(a+b);
//short取值范围-32768~32767
short aa=-32768,bb=32767;
System.out.println(aa);
System.out.println(bb);
//int取值范围-2^31 ~ 2^31-1
int aaa=-2147483648,bbb=2147483647;
System.out.println(aaa);
System.out.println(bbb);
/* //long取值范围-2^63 ~ 2^63-1
System.out.println(-9223372036854775808, 9223372036854775807);
//浮点数根据取值范围又分为两种数据类型float->double java中默认小数为double类型
//float与double取值范围。。。目前不懂就不写了。
//现在知道这么表达小数就行
System.out.println(-0.1, 0.555);*/
}
}
这些数据类型的取值范围都是根据占用的存储空间大小来取值的。
计算机存储设备最小信息单元叫“位(bit)”b
计算机中最小存储单元叫“字节(byte)”B
1B(字节)=8bit
1KB=1024B
1MB=1024KB
1GB=1024MB
1TB=1024GB
byte 占用 1B字节
short 2B
int 4B
long 8B
float 4B
double 8B
char 2B
boolean 1B