Java Reference
In-Depth Information
APPENDIX
B
Java data types
Java's type system is based on two distinct kinds of type: primitive types and object types.
Primitive types are stored in variables directly, and they have value semantics (values are cop-
ied when assigned to another variable). Primitive types are not associated with classes and do
not have methods.
In contrast, an object type is manipulated by storing a reference to the object (not the object
itself). When assigned to a variable, only the reference is copied, not the object.
B.1
Primitive types
The following table lists all the primitive types of the Java language:
Type name
Description
Example literals
Integer numbers
byte
byte-sized integer (8 bit)
24
-2
short
short integer (16 bit)
137
-119
int
integer (32 bit)
5409
-2003
long
long integer (64 bit)
423266353L
55L
Real numbers
float
single-precision floating point
43.889F
double-precision floating point
45.63
double
2.4e5
Other types
char
a single character (16 bit)
'm'
'?'
'\u00F6'
boolean
a boolean value (true or false)
true
false
Notes:
■
A number without a decimal point is generally interpreted as an
int
but automatically con-
verted to
byte
,
short
, or
long
types when assigned (if the value fits). You can declare a
literal as
long
by putting an
L
after the number. (
l
, lowercase
L
, works as well but should be
avoided because it can easily be mistaken for a one (
1
).)
■
A number with a decimal point is of type
double
. You can specify a
float
literal by putting
an
F
or
f
after the number.
■
A character can be written as a single Unicode character in single quotes or as a four-digit
Unicode value, preceded by “
\
u
”.
■
The two boolean literals are
true
and
false
.
Search WWH ::
Custom Search