Java: Primitive data types

The eight primitive data types in Java are:

  • boolean, the type whose values are either true or false
  • char, the character type whose values are 16-bit Unicode characters
  • the arithmetic types:
    • the integral types:
      • byte
      • short
      • int
      • long
    • the floating-point types:
      • float
      • double

Values of class type are references. Strings are references to an instance of class String.

Primitive data types in Java
Type Description Default Size Example Literals
boolean true or false false 1 bit outcome can only be true or false
byte twos complement integer 0 8 bits this can be used to save memories in large arrays, where the memory savings actually matters.
char character \u0000 16 bits a, ß, 4, h, Q
short twos complement integer 0 16 bits for small integers minimum value of -32,768 and a maximum value of 32,767 (inclusive)
int integer 0 32 bits general integer type minimum value of -231 and a maximum value of 231-1
long integer 0 64 bits for bigger integers minimum value of -263 and a maximum value of 263-1
float decimal number 0.0 32 bits for small decimal numbers
double decimal number 0.0 64 bits bigger decimal numbers

Java: Non-primitive data types

This is all the rest of the types you have, like Arrays, Classes and Interfaces. The reason it is not a primitive type is that the value is not stored in the type itself but is a reference to the storing place or an object.