This is a program, Java does not have the implementation of the existing sizeof, the main reason is that the basic data type in Java is a fixed size, so it seems unnecessary to use the keyword sizeof. The idea of implementation is this: there are some simple functions in the Java.lang.Runtime class that can involve memory management: Every Java application have a single instance of classThat allows the application to interface with the environment in which the application is
Runtime
running. The current runtime can is obtained from the
getRuntime
method.
The
example is well written to illustrate the size of the memory that the basic type encapsulates in Java.  
1. A Simple Object object consumes 8 bytes of memory space, because each instance must contain at least some of the most basic operations, such as: Wait ()/notify (), Equals (), hashcode (), and so on  
2. Using an Integer object consumes 16 bytes, while int occupies 4 bytes, which says that the memory consumption is 4 times times larger after the encapsulation  
3. Then long appears to use more space than an integer object, resulting in a long space of 16 bytes.  
That's exactly what the JVM's rules for allocating memory for a basic type encapsulated object are as follows:  
Object occupies memory (8 bytes) + Maximum base type (long) of memory (8 bytes) = 16 bytes.  
JVM enforces the use of 8 bytes as a boundary.  
So the size of the memory for all the basic types of encapsulated objects is 16 bytes. But there are still differences, such as: I The Nteger object consumes 16 bytes of memory, but only takes advantage of the memory (8 bytes) of the object +int the memory (4 bytes) = 12 bytes. and 4 bytes are not used at all. Oh, careful analysis of the night, there are a lot of harvest .
http://blog.csdn.net/dkarthas/article/details/1570469