在windows64位操作系统中,jdk为1.7.0,运行程序验证数据类型大小,代码为:
public class DataTypeByte {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(“byte所占位数” + Byte.SIZE);
System.out.println(“byte所占字节数” + Byte.SIZE/8);
System.out.println(“int所占位数” + Integer.SIZE);
System.out.println(“int所占字节数” + Integer.SIZE/8);
System.out.println(“short所占位数” + Short.SIZE);
System.out.println(“short所占字节数” + Short.SIZE/8);
System.out.println(“float所占位数” + Float.SIZE);
System.out.println(“float所占字节数” + Float.SIZE/8);
System.out.println(“double所占位数” + Double.SIZE);
System.out.println(“double所占字节数” + Double.SIZE/8);
System.out.println(“char所占位数” + Character.SIZE);
System.out.println(“char所占字节数” + Character.SIZE/8);
System.out.println(“long所占位数” + Long.SIZE);
System.out.println(“long所占字节数” + Long.SIZE/8);
}
}
运行结果如图所示
注意:char类型占2个字节,double类型占8个字节
boolean类型在jvm规范中以int类型处理,占4个字节,在boolean数组中占一个字节
小数默认是double类型显示,定义float类型的后面要加f,如float a = 0.9f。