DEV Community

Divya Divya
Divya Divya

Posted on • Edited on

Primitive Data Type:

In Java, a primitive data type is the most basic type of data that stores simple values directly in memory. They are not objects and are used to represent fundamental values like numbers, characters, or boolean states.

Java has 8 primitive data types:

  1. byte

  2. short

  3. int

  4. long

  5. float

  6. double

  7. char

  8. boolean

  • byte:
    Size: 1 byte
    Use: stores small integers (-128 to 127)

  • short:
    Size: 2 bytes
    Use: stores medium integers
    (-32,768 to 32,767)

  • int:
    Size: 4 bytes
    Use: standard integer
    (-2³¹ to 2³¹-1)
    Minimum value = -2³¹ = -2,147,483,648
    Maximum value = 2³¹ - 1 = 2,147,483,647

  • long:
    Size: 8 bytes
    Use: large integer
    (-2⁶³ to 2⁶³-1)
    Minimum value = -2⁶³ = -9,223,372,036,854,775,808
    *Maximum value *= 2⁶³ - 1 = 9,223,372,036,854,775,807

  • float:
    Size: 4 bytes
    Use: decimal number
    (single precision)

  • double:
    Size: 8 bytes
    Use: decimal number
    (double precision)

  • char:
    Size: 2 bytes
    Use: single Unicode character

  • boolean:
    stores true or false

Top comments (0)