3.3 Primitive Types vs. Reference Types

Java’s types are divided into primitive types and reference types. In Chapter 2, you worked with variables of type int—one of the primitive types. The other primitive types are boolean, byte, char, short, long, float and double, each of which we discuss in this book—these are summarized in Appendix D. All nonprimitive types are reference types, so classes, which specify the types of objects, are reference types.

A primitive-type variable can hold exactly one value of its declared type at a time. For example, an int variable can store one integer at a time. When another value is assigned to that variable, the new value replaces the previous one—which is lost.

Recall that local variables are not initialized ...

Get Java™ How To Program (Early Objects), Tenth Edition 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.