Reference Type in AP Computer Science A
In AP Computer Science A, a reference type is any data type that is not primitive (int, double, boolean). A variable of a reference type holds an object reference, which you can think of as the memory address of an object, or null if there is no object.
What is Reference Type?
The CED splits every data type into two categories, primitive or reference (EK 1.2.A.1). Primitives in this course are just int, double, and boolean. Everything else, like String, Scanner, or any class you write, is a reference type (EK 1.2.A.3). Each class defines its own reference type (EK 1.7.A.1).
Here's the key idea. A primitive variable holds the actual value. A reference variable holds an object reference, which is basically the object's memory address (EK 1.12.B.1). Think of it as a slip of paper with a home address written on it, not the house itself. That's why two variables can point to the same object. If you change the object through one variable, the other variable sees the change, because both slips lead to the same house. A reference variable can also hold null, the special literal meaning "no object here" (EK 1.4.A.1, EK 1.13.B.1).
Why Reference Type matters in AP® Computer Science A
Reference types live mostly in Unit 1: Using Objects and Methods, and they come back in Unit 2: Selection and Iteration. They anchor several learning objectives:
- AP Comp Sci A 1.2.A asks you to identify the right data type category (primitive vs. reference) for a specification.
- AP Comp Sci A 1.12.B and AP Comp Sci A 1.13.B ask you to declare variables that store object references.
- AP Comp Sci A 1.4.A covers assigning a new object or
nullto a reference variable. - AP Comp Sci A 2.2.A covers what
==and!=actually compare when the operands are references.
The topic guides teach each of these on their own. This term is the thread running through all of them. Once you get that a reference variable holds an address, null, aliasing, and == behavior all stop being separate rules to memorize.
Keep studying AP® Computer Science A Unit 1
How Reference Type connects across the course
Primitive Data Types (Unit 1)
Topic 1.2 sets up the split. A primitive variable is a box with the value inside. A reference variable is a box holding directions to the object. Every later rule about references follows from this one difference.
Creating Objects with new and Constructors (Unit 1)
In Topic 1.13, new builds an object by calling a constructor (EK 1.13.C.1), and the reference to that object is what gets stored in your variable. The variable never holds the object itself. It holds the address that new handed back.
== and != with Objects (Unit 2)
EK 2.2.A.1 says == on reference types compares the object references, not the contents. So two separate objects with identical data are not ==. The check only returns true when both variables point to the exact same object.
Classes, Objects, and APIs (Unit 1)
A class is the blueprint and an object is one instance built from it (EK 1.12.A.1). Every class, including library classes like String from an API, defines a reference type (EK 1.7.A.1). So whenever you use a class name as a variable's type, you're declaring a reference variable.
Is Reference Type on the AP® Computer Science A exam?
Reference types show up mostly in multiple-choice questions, and you'll be asked to do a few specific things:
- Pick the right category. A stem describes a specification and asks for the most appropriate data type category. One example is storing account balances that need exact decimal arithmetic. You decide whether a primitive fits or whether an object (reference type) is needed.
- Spot correct declarations. Questions ask which set of declarations correctly creates reference variables for different kinds of objects, or which line correctly declares a variable to hold a
Stringreference. The class name is the type, as inString name;. - Trace references. You'll trace code where two variables point to the same object, or where a variable is
null, and determine the output. - Evaluate
==. You'll predict whether==is true for two objects. Remember that it compares references.
No released FRQ has used the term verbatim. But every FRQ that declares an object variable, calls a constructor, or passes an object to a method depends on you handling references correctly.
Reference Type vs Primitive Type
A primitive type (int, double, boolean) stores the actual value directly in the variable. A reference type stores an object reference, basically an address, or null. This matters in practice. Copying a primitive gives you an independent value. Copying a reference gives you a second pointer to the same object. And == compares values for primitives but compares references for objects (EK 2.2.A.1).
Key things to remember about Reference Type
Every data type in AP CSA is either primitive (int, double, boolean) or a reference type, and any class, including String, defines a reference type.
A reference variable holds an object reference, which you can think of as the memory address of the object, not the object itself.
A reference variable can hold null, a special literal that means the variable is not associated with any object.
When two reference variables point to the same object, a change made to the object through one variable shows up when you access it through the other.
Using == on two reference variables checks whether they point to the exact same object, not whether the objects contain the same data.
Objects are usually created with the keyword new plus a constructor call, and the resulting reference is what gets stored in the variable.
Frequently asked questions about Reference Type
What is a reference type in AP Computer Science A?
A reference type is any data type that isn't one of the course's primitives (int, double, boolean). A variable of a reference type holds an object reference, essentially the object's memory address, or null if there is no object (EK 1.12.B.1, EK 1.13.B.1).
Is String a primitive type in Java?
No. String is a class, so it's a reference type, and a String variable holds a reference to a String object. The only primitives tested in AP CSA are int, double, and boolean (EK 1.2.B.1).
Does == check if two objects are equal in AP CSA?
Not the way you might expect. With reference types, == compares the object references (EK 2.2.A.1), so it's only true when both variables point to the same object. Two different objects holding identical data will still give false.
If two variables reference the same object, does reassigning one change the other?
No. Reassigning a variable (for example, b = new Dog(); or b = null;) only changes what that one variable points to. The other variable still references the original object. Only changes made to the shared object itself are visible through both variables.
What's the difference between a reference type and a primitive type?
A primitive variable stores the actual value, like 5 or true. A reference variable stores an address pointing to an object, or null. That's why copying a primitive makes an independent value while copying a reference makes a second pointer to the same object.
Keep studying AP Computer Science A
Connect this key term to the AP exam workflow: review the course, practice questions, and check related study tools.
AP Computer Science A hub
Review units, study guides, and course resources.
AP-style practice
Check this vocabulary in multiple-choice context.
FRQ practice
Apply key concepts in written AP responses.
Score calculator
Estimate the exam score you are working toward.
Cheatsheets
Review the highest-yield facts before practice.
Practice exam
Put the full course together before test day.