Java 基本数据类型大小

Java基本数据类型

  • byte      8bit
  • short    16bit
  • int         32bit
  • long      64bit
  • float      32bit
  • double  64bit
  • char      16bit
	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("Character: " + Character.SIZE/8);       // 2  
        System.out.println("Float: " + Float.SIZE/8);               // 4  
        System.out.println("Double: " + Double.SIZE/8);             // 8  
 
    } 

和c语言相比,java中没有现成的sizeof的实现,原因主要是java中的基本数据类型的大小都是固定的(jvm跨平台),所以看上去没有必要用sizeof这个关键字。

未完待续

参考:https://blog.csdn.net/garfielder007/article/details/53876265

猜你喜欢

转载自blog.csdn.net/qq_36923376/article/details/84586010