Reference Type

In AP Computer Science A, a reference type is a data type whose variables store the memory address of an object rather than the object's actual data, so two variables can point to the same object and a change through one is visible through the other.

Verified for the 2027 AP Computer Science A examLast updated June 2026

What is Reference Type?

A reference type is any non-primitive type in Java, which means classes like String, Scanner, arrays, and any class you write yourself. When you declare String name;, the variable name doesn't hold the text itself. It holds a memory address that points to a String object living somewhere in memory (or it holds null if no object has been assigned yet).

Here's the mental model that makes everything click: a reference variable is a remote control, not the TV. You can have two remotes (Dog a and Dog b = a;) controlling the same TV. Press a button on either one and the same TV changes. That sharing behavior is called aliasing, and it's the reason passing an object to a method lets the method modify the original object, while passing an int never does. The actual object only comes into existence when you use the new keyword to call a constructor.

Why Reference Type matters in AP Computer Science A

Reference types show up the moment AP CSA introduces objects, right after primitive types in the early units, and the distinction never goes away. Every later topic quietly depends on it. Why does == compare addresses for objects but values for ints? Why does modifying an array inside a method change the caller's array? Why does calling a method on a null reference crash with a NullPointerException? All three answers are "because it's a reference type." The CED expects you to know that object variables hold references, that uninitialized references default to null, and that copying a reference does not copy the object. If you don't internalize this early, aliasing bugs in array and ArrayList questions will eat you alive later.

How Reference Type connects across the course

Object (Units 1-2)

The object is the actual thing in memory; the reference variable is just the address that points to it. One object can have many references, and an object with zero references becomes unreachable garbage.

New Keyword (Units 1-2)

Declaring a reference variable creates the remote, but new builds the TV. The new keyword calls a constructor, allocates the object in memory, and hands back the reference you store in your variable.

null (Units 1-2)

null is the special value a reference holds when it points to no object at all. Calling any method on a null reference throws a NullPointerException, one of the most-tested runtime errors in AP CSA.

Abstraction (Units 1-2)

References let you work with an object through its methods without caring where it lives in memory or how its data is stored. That separation between using an object and knowing its internals is abstraction in action.

Is Reference Type on the AP Computer Science A exam?

Reference types are mostly tested through multiple-choice questions that probe whether you know what a reference variable actually stores. Common stems ask what a reference variable holds when no object is assigned (answer: null), how to correctly declare a variable that stores a reference to a String, and which statements about null are true. The trickier MCQs trace aliasing: two variables point to the same object, the code mutates through one, and you have to predict what the other one "sees." Watch for == versus .equals() traps, since == on references compares addresses, not contents. No released FRQ asks you to define "reference type," but every FRQ that passes objects or arrays into methods assumes you understand that the method receives a copy of the reference, so mutations to the object stick.

Reference Type vs Primitive Type

A primitive variable (int, double, boolean) stores the value itself, directly in the variable. A reference variable stores an address that points to an object. Copy a primitive and you get an independent value; copy a reference and you get a second remote control for the same object. This is why int x = y; can never cause one variable to affect another, but Dog a = b; absolutely can.

Key things to remember about Reference Type

  • A reference type variable stores the memory address of an object, not the object's data itself.

  • All non-primitive types in Java are reference types, including String, arrays, ArrayList, and every class you write.

  • Assigning one reference variable to another copies the address, so both variables point to the same object (aliasing).

  • A reference variable that hasn't been assigned an object holds null, and calling a method on it throws a NullPointerException.

  • Using == on reference types compares addresses, so use .equals() to compare object contents like Strings.

  • When you pass an object to a method, the method gets a copy of the reference, which is why it can modify the original object.

Frequently asked questions about Reference Type

What is a reference type in AP Computer Science A?

A reference type is a data type whose variables store the memory address of an object instead of the value itself. All class types in Java, including String, arrays, and your own classes, are reference types.

What's the difference between a reference type and a primitive type?

Primitives like int and double store their value directly in the variable; reference types store an address pointing to an object. Copying a primitive makes an independent copy, while copying a reference makes two variables that share one object.

Does copying a reference variable copy the object?

No. Writing Dog b = a; copies only the address, so a and b point to the same Dog object. To get a separate object you'd need to construct a new one with the new keyword.

What does a reference variable store before it's assigned an object?

It holds null, meaning it points to no object. If you call a method through that null reference, your program crashes with a NullPointerException, which is a frequent MCQ answer choice.

Is String a reference type or a primitive in Java?

String is a reference type, since it's a class, not a primitive. That's why == on two Strings compares addresses and you should use .equals() to compare their actual text on the AP exam.