0% found this document useful (0 votes)
13 views2 pages

New Microsoft Word Document

In Java, an empty class object has a minimum size that is not zero, typically 8 to 16 bytes depending on the JVM architecture and options. This size is due to the object header and alignment requirements, rather than user-defined fields. The memory footprint can vary based on factors such as JVM implementation and whether compressed oops are used.

Uploaded by

rahulbadhe630
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

New Microsoft Word Document

In Java, an empty class object has a minimum size that is not zero, typically 8 to 16 bytes depending on the JVM architecture and options. This size is due to the object header and alignment requirements, rather than user-defined fields. The memory footprint can vary based on factors such as JVM implementation and whether compressed oops are used.

Uploaded by

rahulbadhe630
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

type identification125.

Key Points
 Minimum Size:
The size of an empty class object is not zero. On
most modern JVMs (e.g., HotSpot), the minimum
size is typically 16 bytes on a 64-bit JVM without
compressed oops, and can be as low as 8 bytes on
some 32-bit JVMs12.
 Why Not Zero?
The memory footprint comes from the object
header and alignment/padding requirements, not
from user-defined fields125.
 JVM and Platform Dependent:
The exact size can vary based on:
 JVM implementation
 32-bit vs 64-bit architecture
 JVM options like -XX:+UseCompressedOops1
 Implications:
Creating many instances of an empty class can still
consume significant memory due to this
overhead12.
Example
java
class EmptyClass {}
EmptyClass obj = new EmptyClass();
Even though EmptyClass has no fields, obj will typically
occupy 16 bytes (on a standard 64-bit JVM) due to the
object header and alignment12.
Summary Table
JVM Type Typical Empty Object Size

32-bit JVM 8 bytes

64-bit JVM 16 bytes

64-bit (compressed oops) 12 bytes

In short:
An empty class in Java always has a nonzero memory
footprint—usually 8 to 16 bytes—because of JVM object
metadata, not because of user-defined fields

You might also like