For the complete documentation index, see llms.txt. This page is also available as Markdown.

Reference Materials

Java Data Type Size Chart

1. Primitive Data Types

Data Type
Size (bits)
Size (bytes)
Default Value
Range
Notes

byte

8

1

0

-128 to 127

Smallest integer type

short

16

2

0

-32,768 to 32,767

Compact integer

int

32

4

0

-2^31 to 2^31-1 (~±2.14B)

Common for integers

long

64

8

0L

-2^63 to 2^63-1

Use L suffix

float

32

4

0.0f

±3.4E+38 (~7 digit precision)

Use f suffix

double

64

8

0.0d

±1.7E+308 (~15 digit precision)

Default for decimals

char

16

2

\u0000

0 to 65,535

Represents Unicode characters

boolean

1 (JVM dependent)

JVM-defined (1 byte min)

false

true or false

Actual size varies (not directly defined in spec)

JVM may pad primitives and objects for alignment — actual memory usage may exceed declared size.

2. Reference Types (Object Overhead)

Component
64-bit JVM (compressed oops)
Notes

Object header

12 bytes

Includes mark word & class pointer

Object reference

4 bytes (compressed), 8 bytes (uncompressed)

Pointers to other objects

Array header

16 bytes (object header + length)

All arrays are objects

Alignment padding

Align to 8-byte boundary

JVM aligns for performance

3. Common Object Sizes (Estimated)

Object Type
Approx Size (bytes)
Comments

Integer

~16 bytes

Object wrapping a primitive int

Long

~24 bytes

Larger due to 64-bit value

String (empty)

~40 bytes

Includes char array reference

UUID

~32 bytes

2 long values internally

ArrayList (empty)

~24 bytes

Plus internal array (default size 10)

Tips for Memory-Efficient Code

  • Prefer primitives (int, long) over wrappers (Integer, Long) in large collections.

  • Use record instead of class for data holders (Java 14+).

  • Use final where possible to help the JVM with optimization.

  • Avoid deep object graphs in caches — flatten where feasible.

  • Use off-heap caching (e.g., Redis, Ehcache) for large datasets.

Last updated