Java Reference
In-Depth Information
Chapter
6
Reference on Primitive Types
OBJECTIVES
•
Provide a reference on Java's primitive types.
INTRODUCTION
A
type
describes a set of values together with operations on them. For example,
mathematical type
integer
describes the set of all integers together with opera-
tions like addition
+
and multiplication
*
. Each variable in a Java program has a
type, which defines the values that can be associated with the variable. Each
expression has a type, which depends on the type of its operands.
Java has two kinds of types:
primitive types
and
class types
. Primitive types
are built into Java. A class type, or simply class, is defined in a program, by a
class definition
. In this chapter, we describe the primitive types.
Below, we list the primitive types of Java, along with the set of values in
them and the amount of memory used to hold their values.
Type
Range of values
Memory used
1 byte (8 bits)
byte
-128..127
-2
15
..2
15
-1
2 bytes (16 bits)
short
-2
31
..2
31
-1
4 bytes (32 bits)
int
-2
63
..2
63
-1
8 bytes (64 bits)
long
-3.4028235E38
to
-1.4E-45
4 bytes (32 bits)
float
1.4E-45
to
3.4028235E38
-1.7676931348623157E308
to
0
8 bytes (64 bits)
double
0
to
1.7676931348623157E308
Unicode characters
2 bytes (16 bits)
char
false
,
true
1 byte
boolean
Search WWH ::
Custom Search