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.
| Type | Description | Default | Size | Example Literals |
|---|---|---|---|---|
| boolean | true or false | false | 1 bit | true, false |
| byte | twos complement integer | 0 | 8 bits | (none) |
| char | Unicode character | \u0000 | 16 bits | 'a', '\u0041', '\101', '\\', '\'', '\n', 'ß' |
| short | twos complement integer | 0 | 16 bits | (none) |
| int | twos complement integer | 0 | 32 bits | -2, -1, 0, 1, 2 |
| long | twos complement integer | 0 | 64 bits | -2L, -1L, 0L, 1L, 2L |
| float | IEEE 754 floating point | 0.0 | 32 bits | 1.23e100f, -1.23e-100f, .3f, 3.14F |
| double | IEEE 754 floating point | 0.0 | 64 bits | 1.23456e300d, -1.23456e-300d, 1e1d |
No comments:
Post a Comment