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:
- the floating-point types:
Values of class type are references. Strings are references to an instance of class String.
Values of type
boolean are not converted implicitly or explicitly (with casts) to any other type. But the programmer can easily write conversion code:
final int i = b?1:0;
final double d = b?1.0:0.0;
final boolean b = i>0?true:false;
Primitive data types in Java
| 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 |
Comments
Post a Comment