Primitive Data Types in Java

2 min read ·

Primitive data types are the most basic data types in Java. They directly store simple values.
Java has 8 primitive data types:
  • byte
  • short
  • int
  • long
  • float
  • double
  • char
  • boolean

byte Data Type

  • Size: 1 byte
  • Range: -128 to 127
Used when saving memory in large arrays.

short Data Type

  • Size: 2 bytes
  • Range: -32,768 to 32,767
Used for smaller integer values.

int Data Type

  • Size: 4 bytes
  • Most commonly used integer type
Default choice for whole numbers.

long Data Type

  • Size: 8 bytes
  • Used for very large numbers
Must add L at the end for large values.

float Data Type

  • Size: 4 bytes
  • Stores decimal numbers
  • Must end with f

double Data Type

  • Size: 8 bytes
  • More precise than float
  • Default choice for decimals

char Data Type

  • Size: 2 bytes
  • Stores single character
  • Uses single quotes

boolean Data Type

  • Stores only true or false
Used in conditions and decision making.
Learn Java Primitive Data Types in Java | Java Course