Introduced:
There are 8 basic types in Java, namely, Boolean, Char, Byte, short, int, long, float, double. Their lengths are fixed, not objects. For situations where it is necessary to treat a base type as an object, Java provides a wrapper class, which has the advantage that the Java compiler and the runtime are easier to optimize. Because of Java portability, each type is the same size on different platforms.
Code implementation:
PackageSelf ;/*** Created by Jimmy on 2015/5/18.*/ Public classsizeof { Public Static voidMain (string[] args) {System.out.println ("Integer:" + INTEGER.SIZE/8);//4System.out.println ("Short:" + SHORT.SIZE/8);//2System.out.println ("Long:" + LONG.SIZE/8);//8System.out.println ("Byte:" + BYTE.SIZE/8);//1System.out.println ("Character:" + CHARACTER.SIZE/8);//2System.out.println ("Float:" + FLOAT.SIZE/8);//4System.out.println ("Double:" + DOUBLE.SIZE/8);//8//System.out.println ("Boolean:" + BOOLEAN.SIZE/8); //True/false }}
Output:
1 integer:42 short:23 long:84 byte:15 character:26 float:4 7 Double:8
Length of type in Java