2.2.Primitive Data Types
The Java programming language is statically-typed, meaning that all variables must be declared before their utilization. This includes specifying the variable’s type and name, such as “gear” which instructs a program to use a field named “gear” with numerical data. The language supports eight primitive data types: byte, brief, int, float, double, boolean, and char.
Byte is an 8-bit signed two’s complement integer, ideal for optimizing memory usage in extensive arrays. Short is a 16-bit signed two’s complement integer, suitable for memory conservation in large arrays. Int is a 32-bit signed two’s complement integer, typically used for integral values. Long is a 64-bit signed two’s complement integer, suitable for a range of values exceeding int.
Float is a single-precision 32-bit IEEE 754 floating point data type, recommended for memory savings in large arrays of floating point numbers. Double is a 64-bit IEEE 754 floating point with double precision, typically used for decimal values but not precise values like currency. Boolean is a boolean data type limited to true and false, suitable for simple flags monitoring true/false conditions.
Char is a single 16-bit Unicode character, represented by the char data type. The Java Language Specification specifies its range of values in section 4.2.3, but it is not suitable for precise values like currency.
The Java programming language also offers specialized support for character strings through the java.lang module. The String class generates a new String object by enclosing a character string within double quotes. Although not technically a primitive data type, it is likely perceived as such due to the language’s unique support.