The sizeof operator is not available in Java, but sometimes you may want to know the size of Java objects. The size of an object depends on the number of header words in an object, pointer size (32/64 bit), and alignment variations that make object size dependent on VM implementation.
With JDK 5.0, you can get size in two new ways without using profilers or native agents:
Use java.lang.instrument.Instrument.getObjectSize API.
Use jmap -histo to get object histogram. For each class, jmap prints number of objects and total size in bytes occupied by those objects. Divide total size by number of objects to get size of an individual object.