B.5 Primitive Types vs. Reference Types
Java’s types are divided into primitive types and reference types. The primitive types are boolean
, byte
, char
, short
, int
, long
, float
and double
. All nonprimitive types are reference types, so classes, which specify the types of objects, are reference types.
A primitive-type variable can store exactly one value of its declared type at a time. For example, an int
variable can store one whole number (such as 7) at a time. When another value is assigned to that variable, its initial value is replaced. Primitive-type instance variables are initialized by default—variables of types byte
, char
, short
, int
, long
, float
and double
are initialized to 0, and variables of type boolean
are initialized to false
Get Android How to Program, 3/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.