Java编程基础1-各个级别类型所占内存空间大小

       看了很多乱七八糟的设计模式的书,最后突然发现自己把最基础的东西忘记了,所以特地温习了一下,记录下来,与大家共勉。

       在Java中可以通过Integer.SIZE这样的方法直接查看基本类型所占内存空间的大小。通过一下程序就能够查看了:

 

	        System.out.println("Integer:"+Integer.SIZE);
		System.out.println("Byte:"+Byte.SIZE);
		System.out.println("Long:"+Long.SIZE);
		System.out.println("Short:"+Short.SIZE);
		System.out.println("Character:"+Character.SIZE);
		System.out.println("Double:"+Double.SIZE);
		System.out.println("Float:"+Float.SIZE);

     输出结果是(单位是bit):

      Integer:32(4个字节)
      Byte:8(一个字节)
      Long:64(8个字节)
      Short:16 (2个字节)
      Character:16 (2个字节)
      Double:64 (8个字节)
      Float:32(4个字节)

      Boolean类型有点奇怪,官方文档是这么说的:This data type represents one bit of information,
 but its "size" isn't something that's precisely defined.(这种数据类型保存一位的信息,但是它的大小却不是精确定义的。

你可能感兴趣的:(java,基础)