Java Building Blocks: Intrinsic Data Types

Primitives and core object types

Overview

Java values include primitive types and object references. The former—along with arrays and the String class from the latter group—are intrinsic to the Java language itself, and include the following, broken down into groups.

Much of the information below is also available, in a slightly different form, in “Java Primitive Types”.

Boolean

boolean

One of just two possible values: true and false.

In many languages, numeric values can be treated as Boolean values and vice-versa;1 this is not the case in Java.

Numeric

byte

8-bit signed (positive, negative, or zero) integer value in the range $\left[ -128 \ldotp \ldotp 127 \right]$ (these limits are the values of the constants Byte.MIN_VALUE and Byte.MAX_VALUE).

short

16-bit signed integer value in the range $\left[ -32,768 \ldotp \ldotp 32,767 \right]$ (that is, Short.MIN_VALUE through Short.MAX_VALUE).

char

16-bit unsigned (non-negative) integer value, in the range $\left[ 0 \ldotp \ldotp 65,636 \right]$. A string representation of a char consists not of the digits of its numeric value, but of the Unicode character at the code point given by that numeric value.

The limits of this type are given by Character.MIN_VALUE and Character.MAX_VALUE. However, in an environment such as JShell, char values will be shown as their string representations: Character.MIN_VALUE is the NUL character, which has no visible representation in most contexts, but will typically be displayed in JShell as \000; no Unicode character has the code point Character.MAX_VALUE, so it will typically be displayed in JShell as ?.

int

32-bit signed integer value in the range $\left[ -2,147,483,648 \ldotp \ldotp 2,147,483,647 \right]$ (or Integer.MIN_VALUE through Integer.MAX_VALUE).

long

64-bit signed integer value in the range $\left[ -9,223,372,036,854,775,808 \ldotp \ldotp 9,223,372,036,854,775,807 \right]$ (Long.MIN_VALUE through Long.MAX_VALUE).

Floating-point

float

32-bit floating-point value, encoded using the IEEE float32 (single-precision) format, with a value in the interval $\left( -2^{128}, 2^{128} \right)$, and with ~7 significant digits of precision. Float.MAX_VALUE gives the maximum value of this type, while Float.MIN_VALUE gives the smallest positive value (approximately 1.4E-45) that can be represented by this type.

double

64-bit floating-point value, encoded using the IEEE float64 (double-precision) format, with values in the interval $\left( -2^{1024}, 2^{1024} \right)$, with ~16 significant digits of precision. Double.MAX_VALUE gives the maximum value of this type, while Double.MIN_VALUE gives the smallest positive value (approximately 4.9E-324) that can be represented by this type.

String (character sequence)

String

A sequence of Unicode characters, with a length in the range $\left[ 0 \ldotp \ldotp 2,147,483,647 \right]$ (expressed a number of chars). This is the only object type for which the Java compiler recognizes a literal value as completely specifying an instance.

Arrays

A contiguous sequence of homogenous values, with each element accessed by index position. While element types are homogenous within any given array, arrays can be defined to hold virtually any type—primitive values or object references (including references to other arrays, which is how multidimensional arrays are defined in Java).

  1. In programming languages that allow numeric values to be treated as Boolean values and vice versa, zero (0) is typically mapped to false, and any non-zero value to true; in the opposite direction, false is treated as 0, and true as 1 or -1 (depending on the language).