The Java value type is also known as the primitive data type. Table 7.1 shows the Java primitives.
Variables can be declared as a primitive type. Depending on the scope where they are declared, they must be initialized. For example, you must initialize local method variables as shown here:
int age = 10; long population = 100000L; float price = 12.45f; double count = 6.45d;
Keyword | Description | Size/Format |
---|---|---|
Byte | Byte-length integer | 8 bits |
Short | Short integer | 16 bits |
Int | Integer | 32 bits |
Long | Long integer | 64 bits |
Float | Single-precision floating point | 32-bit IEEE 754 |
Double | Double-precision floating point | 64-bit IEEE 754 |
Char | A single character | 16-bit Unicode character |
Boolean | A Boolean value | True or false |
Suffixing a float literal with f or F or a long literal with l or L improves the clarity of the code, although it is not required. Primitive data types are passed by value, so changes made to the primitive's value inside a method are local to that method and are not retained after the method call completes.
3.14.15.94