Describe the primitive types and range of values associated with each type.
Java variables may store the values of primitive types or references to objects. Java supports the following eight primitive types:
boolean - Consists of the boolean values true and false.
byte - Supports 8-bit integer values from -128 to 127.
char - Supports 16-bit Unicode characters whose values range from 0 to 216 - 1.
short - Supports 16-bit integer values whose values range from -(215) to 215 - 1.
int - Supports 32-bit integer values whose values range from -(231) to 231 - 1.
long - Supports 64-bit integer values whose values range from -(263) to 263 - 1.
float - Supports 32-bit floating point values whose values range from Float.MIN_VALUE to Float.MAX_VALUE.
It also includes the values Float.NaN (not a number), Float.NEGATIVE_INFINITY, and Float.POSITIVE_INFINITY.
double - Supports 64-bit floating point values whose values range from Double.MIN_VALUE to Double.MAX_VALUE.
It also includes the value Double.NaN (not a number), Double.NEGATIVE_INFINITY, and Double.POSITIVE_INFINITY.
The NaN (not a number) value is used with floating point types to indicate the result of an undefined mathematical operation.
The values POSITIVE_INFINITY and NEGATIVE_INFINITY are used to represent infinite values.
Remember the ranges of each of the primitive types. You will see questions on the certification exam that test your knowledge of them.
A variable defined as one of the primitive data types is a primitive variable. Primitive data types, as the name suggests, are the simplest data types in a programming language. In the Java language, they are predefined.
The names of the primitive types are quite descriptive of the values that they can store. Java defines the following eight primitive data types:
Examine figure 2.6 and try to match the given value with the corresponding type.
Unicode: A 16-bit character set that includes ASCII and provides support for international characters.