Int:4 bytes
Short:2 bytes
Long:8 bytes
Byte:1 bytes
Character:2 bytes
Float:4 bytes
Double:8 bytes
Boolean: The system does not provide a size method;
public class Calcsizof {/** * @param args */private static void Calsize () { System.out.println ("Integer:" + INTEGER.S IZE/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 System.out.println ("Boolean:" + boolean.tostring (false)); } public static void Main (string[] args) {//TODO auto-generated method stubcalcsizof calcsizof= new Calcsizof (); Calcsizof.calsize ();}}
Operation Result: Console output
Integer:4
Short:2
Long:8
Byte:1
Character:2
Float:4
Double:8
Boolean:false
For more information on the footprint of the encapsulated object, please refer to
http://blog.csdn.net/ithomer/article/details/7310008
Number of bytes in Java for each basic data type