Java包括两大数据类型:基本类型和引用类型。
基本类型或原生类型(primitive type)包括:
整数类型:byte(8位), short(16位), int (32位) , long(64位) (值为有符号二进制补码整数)
数据类型 | 所占位数 | 数的范围 |
byte | 8 | -27~27-1 |
short | 16 | -215~215-1 |
int | 32 | -231~231-1 |
long | 64 | -263~263-1 |
可仿照下列代码编程进行验证:
public class IntegerExample {
public static void main(String[] args) {
System.out.println(Integer.MAX_VALUE);
System.out.println(Integer.MIN_VALUE);
}
}
浮点类型:float,double
数据类型 | 所占位数 | 数的范围 |
float | 32 | 1.4E-45 ~3.4E+38 |
double | 64 | 4.9E-324 ~1.7E308 |
字符类型:char (16位无符号整数,使用Unicode字符集)
布尔类型:boolean (值为true或false,C++ 的布尔类型是bool)
引用类型(reference type)包括:
类类型
接口类型
数组类型