Skip to Content
Java Pocket Guide, 4th Edition
book

Java Pocket Guide, 4th Edition

by Robert Liguori, Patricia Liguori
August 2017
Intermediate to advanced content levelIntermediate to advanced
290 pages
4h 10m
English
O'Reilly Media, Inc.
Content preview from Java Pocket Guide, 4th Edition

Chapter 4. Reference Types

Reference types hold references to objects and provide a means to access those objects stored somewhere in memory. The memory locations are irrelevant to programmers. All reference types are a subclass of type java.lang.Object.

Table 4-1 lists the five Java reference types.

Table 4-1. Reference types
Reference type Brief description

Annotation

Provides a way to associate metadata (data about data) with program elements.

Array

Provides a fixed-size data structure that stores data elements of the same type.

Class

Designed to provide inheritance, polymorphism, and encapsulation. Usually models something in the real world and consists of a set of values that holds data and a set of methods that operates on the data.

Enumeration

A reference for a set of objects that represents a related set of choices.

Interface

Provides a public API and is “implemented” by Java classes.

Comparing Reference Types to Primitive Types

There are two type categories in Java: reference types and primitive types. Table 4-2 shows some of the key differences between them. See Chapter 3 for more details.

Table 4-2. Reference types compared with primitive types
Reference types Primitive types

Unlimited number of reference types, as they are defined by the user.

Consists of boolean and numeric types: char, byte, short, int, long, float, and double.

Memory location stores a reference to the data.

Memory location stores actual data held by the primitive type. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java 8 Pocket Guide

Java 8 Pocket Guide

Robert Liguori, Patricia Liguori
Java 11 Cookbook - Second Edition

Java 11 Cookbook - Second Edition

Nick Samoylov, Mohamed Sanaulla

Publisher Resources

ISBN: 9781491938683Errata Page