Java Fundamentals  «Prev  Next»


Lesson 6Primitive Types
ObjectivePrimitive types and range of values

Primitive types in Java

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:
  1. boolean - Consists of the boolean values true and false.
  2. byte - Supports 8-bit integer values from -128 to 127.
  3. char - Supports 16-bit Unicode [1] characters whose values range from 0 to 216 - 1.
  4. short - Supports 16-bit integer values whose values range from -(215) to 215 - 1.
  5. int - Supports 32-bit integer values whose values range from -(231) to 231 - 1.
  6. long - Supports 64-bit integer values whose values range from -(263) to 263 - 1.
  7. 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.
  8. 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.

Primitive Variables

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:
  1. char
  2. byte
  3. short
  4. int
  5. long
  6. float
  7. double
  8. boolean
Examine figure 2.6 and try to match the given value with the corresponding type.
Match value with data type
Figure 2.6 Match the given value with the corresponding type.

[1]Unicode: A 16-bit character set that includes ASCII and provides support for international characters.

SEMrush Software