Java Primitive Data Types

The Shortcut
2 min readDec 30, 2022

--

In Java, there are eight primitive data types:

  1. boolean: a data type that can only take the values true or false
  2. char: a data type that represents a single character
  3. byte: a data type that represents an 8-bit signed integer
  4. short: a data type that represents a 16-bit signed integer
  5. int: a data type that represents a 32-bit signed integer
  6. long: a data type that represents a 64-bit signed integer
  7. float: a data type that represents a single-precision 32-bit floating point number
  8. double: a data type that represents a double-precision 64-bit floating point number

Primitive data types are the most basic data types available in Java, and are used to represent simple values such as numbers, characters, and boolean values. They are not objects and do not have any methods associated with them.

For example, you could declare a variable of type int as follows:

int myInt = 5;

You can also cast a value of one primitive data type to another, as long as the value can be accurately represented in the target data type. For example:

int myInt = 5;
long myLong = myInt; // okay, because int fits within the range of long

However, if the value is too large to be represented in the target data type, it will cause an error:

long myLong = 999999999999;
int myInt = myLong; // error, because long is too large to fit in an int

Find out more about Java here:

--

--

The Shortcut

Short on time? Get to the point with The Shortcut. Quick and concise summaries for busy readers on the go.