Memory Size of Data Types

1 min read ·

Each primitive type has a fixed memory size.
Data TypeSize
byte1 byte
short2 bytes
int4 bytes
long8 bytes
float4 bytes
double8 bytes
char2 bytes
boolean1 bit logical

Why Memory Matters

Choosing the correct data type helps:
  • Optimize memory usage
  • Improve performance
  • Avoid overflow errors
Example:
Using byte instead of int in large arrays can reduce memory usage.