数据类型分为两种:基本数据类型和引用数据类型。
基本数据类型
有哪些:byte,short,int,long,float,double,char,boolean
整数类型:byte,short,int,long
小数类型:float,double
字符类型:char
布尔类型:boolean
不同数据类型的数据范围不同:
byte:取值范围为【-128,127】
short:取值范围为【-32768,32767】
int:取值范围约21亿
long:取值范围约2^31-1float:取值范围为3.401298e-38-3.4028231e+38
double:取值范围为-4.9000000e-324-1.797693e+308
char:取值范围为0-65535
boolean:true,false
引用数据类型
除了八大基本数据类型外其他的都是引用数据类型
区别
基本数据类型定义的变量存储的实际的,实实在在的数据值,例如:int a=10;
引用数据类型定义的变量存储的是地址值,例如:数组
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {public static void main(String[] args) {int a=10;System.out.println(a);int []arr={0,1,2};System.out.println(arr);}
}
输出结果为:
10
[I@b4c966a