今天笔试中java题: (1) public static void main (String []args) { Integer a = new Integer(1); Integer b = new Integer(1); int c = 1; Integer e = 1; System.out.println("a==b:"+(a==b)); System.out.println("a==c:"+(a==c)); System.out.prin
Int: 4 字节 Short: 2字节 Long: 8字节 Byte: 1字节 Character: 2字节 Float: 4字节 Double: 8字节 Boolean:系统没有提供Size方法; [java]
view plain copy public class Calcsizof {
/**
* @param args
*/
private static void calSize() {
System.out.println("Integer: " + Integer.SIZE/8);
// 4
System.out.println("Short: " + Short.SIZE/8);
// 2
System.out.println("Long: " + Long.SIZE/8);
// 8
System.out.println("Byte: " + Byte.SIZE/8);
// 1
System.out.println("Charbyte 1个字节(主要是节省内存控件,在进行i/o传输的时候可以使用) short 2个字节(不常用) int 4个字节(常用于控制循环语句) long 8个字节(计算非常大的数是,int不足以满足容纳大小,如果long还不够就是用BigInteger) char 2个字节(Java使用Unicode字符集表示字acter: " + Character.SIZE/8);
// 2
System.out.println("Float: " + Float.SIZE/8);
// 4
System.out.println("Double: " + Double.SIZE/8);
// 8
System.out.println("Boolean: " + Boolean.toString(false));
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Calcsizof calcsizof= new Calcsizof();
Calcsizof.calSize();
}
}
运行结果:console 输出 Integer: 4 Short: 2 Long: 8 Byte: 1 Character: 2 Float: 4 Double: 8 Boolean: false 更多地封装后的Object的占用空间的分析 请参考