Java Reference
In-Depth Information
We now turn our attention to a discussion on garbage collection, which fi rst requires an
understanding of the differences between reference types and primitive types.
Reference vs. Primitive Types
Java applications contain two types of data:
primitive types
and
reference types
. In this
section, we will discuss the differences between a primitive type and a reference type. The
differences are important when we discuss garbage collection later in this chapter.
Primitive Types
Java has eight built-in data types, referred to as the
Java primitive types
. These eight data
types represent the building blocks for Java objects, because all Java objects are just a
complex collection in memory of these primitive data types. The SCJP exam assumes you
are well versed in the eight primitive data types, their size, and what can be stored in them.
Table 1.1 shows the Java primitive types together with their size in bytes and the range of
values that each holds.
TABLE 1.1
The Java Primitive Data Types
Primitive Type
Size
Range of Values (inclusive)
byte
8 bits
-128 to 127
short
16 bits
-32768 to 32767
int
32 bits
-2147483648 to 2147483647
long
64 bits
-9223372036854775808 to 9223372036854775807
float
32 bits
2
-149
to (2 - 2
-23
) · 2
127
double
64 bits
2
-1074
to (2 - 2
-52
) · 2
1023
char
16 bits
'\u0000' to '\uffff' (0 to 65535)
boolean
unspecified
true or false
Search WWH ::
Custom Search