Reference in AP Computer Science A

In AP Computer Science A, a reference is the value stored in a variable of a reference type: essentially the memory address of an object, not the object itself (EK 1.12.B.1). Two variables can hold references to the same object, so changing the object through one variable is visible through the other.

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

What is reference?

A reference is what actually lives inside a variable like Student s or ArrayList<String> list. The variable doesn't contain the object. It contains a pointer to where the object sits in memory. The CED puts it plainly in EK 1.12.B.1: a variable of a reference type holds an object reference, "which can be thought of as the memory address of that object."

Think of it like a home address written on a sticky note. Copying the sticky note (list3 = list1) doesn't build a second house. It gives you two notes pointing at the same house, so if someone repaints the house, both notes lead you to the repainted version. That's why list3 = list1; list1.add("Java"); means list3 sees "Java" too. This is called aliasing, and it's the single biggest reason references trip people up. A reference variable can also hold null, meaning it points at nothing yet, and calling a method on it throws a NullPointerException.

Why reference matters in AP® Computer Science A

References live in Topic 1.12 (Objects: Instances of Classes) in Unit 1: Using Objects and Methods, under learning objective 1.12.B: develop code to declare variables to store reference types. They sit right next to 1.12.A, which covers classes as blueprints and objects as instances. A class is the blueprint, new builds the object, and the reference is your handle on that object.

This concept never stops mattering. Every String, every ArrayList, every object you create in an FRQ is accessed through a reference. If you don't understand that = copies the address (not the object), you'll misread MCQ trace questions about aliasing, mutability, and null, and you'll be confused about why methods can change an object you passed in.

How reference connects across the course

Object reference (Unit 1)

This is the exact CED phrase for the value a reference variable holds. "Reference" and "object reference" are the same idea: the variable stores the address, and the object lives elsewhere in memory.

Attributes and behaviors of objects (Unit 1)

A reference is useless on its own. Its whole job is letting you use the dot operator to reach an object's attributes and call its behaviors, like student1.getName(). No reference, no access.

Aliasing in arrays and ArrayLists (Unit 4)

Arrays and ArrayLists store references, and array/list variables are themselves references. So list2 = list1 makes two names for one list, and passing an array to a method lets that method change the original. The 2018 ArrayTester FRQ leans on exactly this.

Primitive types like int and double (Unit 1)

Primitives are the contrast case. An int variable holds the actual value, so copying it makes a true independent copy. A reference variable holds an address, so copying it just makes another pointer to the same object.

Is reference on the AP® Computer Science A exam?

References are tested constantly even when the word "reference" never appears in the question. MCQs love trace problems where two variables point at the same object, like ArrayList<String> list3 = list1; followed by mutations, and ask what each variable "sees" afterward. Another classic stem assigns student1 = student3; and prints through both names, or declares a variable without initializing it and asks what happens when you call a method on null.

On FRQs, you use references every time you write new and store the result, like building a WordPair object (2018 Q2) or an ArrayList<Integer> of digits (2017 Q1). The 2018 ArrayTester question requires understanding that a 2D array parameter is a reference, so you're reading the caller's actual array. What you must DO: declare reference variables correctly (String s = new String(...) or String s = "..."), predict aliasing effects, recognize NullPointerException situations, and remember that reassigning a reference doesn't destroy the old object's data, it just points your variable somewhere else.

Reference vs primitive variable

A primitive variable (like int x = 5) stores the value itself, so int y = x makes a fully independent copy. A reference variable (like Rectangle r) stores an address, so Rectangle r2 = r creates a second name for the same object. Change the object through r2 and r sees it too. With primitives, changes never travel between variables; with references, they do whenever both point at the same object.

Key things to remember about reference

  • A reference variable holds the memory address of an object, not the object itself (EK 1.12.B.1).

  • Assigning one reference variable to another (list3 = list1) copies the address, so both variables now point to the same object, and mutations through either one are visible through both.

  • A reference can hold null, which means it points to no object, and calling any method through a null reference throws a NullPointerException.

  • Primitives copy values; references copy addresses. That single difference explains most aliasing and parameter-passing questions on the exam.

  • Reassigning a reference to a new object doesn't delete the original object, it just makes your variable point somewhere else.

  • Every object in Java (Strings, ArrayLists, custom classes) is accessed through a reference, so this Unit 1 idea shows up in every later unit.

Frequently asked questions about reference

What is a reference in AP Computer Science A?

A reference is the value a variable of a reference type holds, best thought of as the memory address of an object (EK 1.12.B.1, Topic 1.12). The variable points to the object rather than containing it.

Does setting two variables equal to each other copy the object in Java?

No. With reference types, obj2 = obj1 copies only the address, so both variables point to the same single object. If you add an element through obj1, obj2 sees it too. To get an independent copy, you'd have to construct a new object.

What's the difference between a reference and a primitive in Java?

A primitive variable like int or double stores its actual value, while a reference variable like String or ArrayList stores the address of an object in memory. Copying a primitive makes an independent value; copying a reference makes an alias to the same object.

What happens if I call a method on a null reference?

Java throws a NullPointerException at runtime. A declaration like Student student2 = null; means the variable exists but points to no object, so student2.getName() crashes. This is a favorite MCQ trap.

Is the word "reference" actually tested on the AP CSA exam?

Yes, both directly and indirectly. It's named in learning objective 1.12.B, and aliasing trace questions are MCQ staples. Every FRQ also depends on it, since released questions like 2017 Q1 (Digits) and 2018 Q2 (WordPair) require constructing objects and working through references.