Keywords: current

Next: 1.2.1.0.1 Numeric Constants Up: 1.2 Java Data Types Previous: 1.2 Java Data Types

## 1.2.1 Primitive Types

All primitive values belong to one of eight primitive types: `int`, `float`, `boolean`, `char`, `byte`, `short`, `long`, and `double`. Four of these types designate different sizes of bounded integers:

- `byte` contains the integers ranging from -128 to 127;
- `short` contains the integers ranging from -32768 to 32767;
- `int` contains the integers ranging from -2147483648 to 2147483647; and
- `long` contains the integers ranging from

  > `-9223372036854775808`

  to

  > `9223372036854775807`.

In practice, only three of these primitive types are widely used: `int`, `boolean`, and `double`.

A program should never contain explicit references to any of the specific integer constants given above. They can always be replaced by references to the `static final` fields `MIN_VALUE` and `MAX_VALUE` in the corresponding ``wrapper'' class: `Byte`, `Short`, `Integer` or `Long`. Java has a built-in wrapper class for each primitive type. For example, in the wrapper class `Integer` corresponding to the primitive type `int`, `MIN_VALUE = -2147483648` and `MAX_VALUE = 2147483647`. For more information on the primitive wrapper classes, read the on-line documentation from Sun Microsystems for the built-in class `Number` and its subclasses.

The `boolean` type has two values `true` and `false`. The `char` type supports the Unicode character set which includes all conventional ASCII characters plus almost any foreign character imaginable. The `char` type is rarely used in Java programs because a flexible `String` object type is built-in to the language. The remaining two types `float` and `double` are used for approximate computations involving real numbers; they denote standard IEEE 32-bit and 64-bit formats, respectively.

Subsections

- - 1.2.1.0.1 Numeric Constants
  - 1.2.1.0.2 Conversions Between Types [Optional]

Next: 1.2.1.0.1 Numeric Constants Up: 1.2 Java Data Types Previous: 1.2 Java Data Types