01
Overview

Objects: the building blocks of Java programs.

In Java, almost everything you work with — Strings, ArrayLists, your own custom types — is an object built from a class.

An object is a self-contained bundle of data and behavior. The data lives in instance variables, and the behavior lives in methods. The blueprint that defines what an object looks like and what it can do is called a class.

Java is an object-oriented language: programs are built by creating objects from classes and asking those objects to do things. Even something as simple as a String is an object with its own methods like length() and substring().

On the AP exam, you'll be expected to know how to create objects, store references to them, call methods on them, and recognize the difference between a reference and the object it points to.

02
Core Concept

Classes describe; objects exist.

A class is a blueprint. An object is one concrete instance of that blueprint.

Creating an object

To create an object in Java, use the new keyword followed by a constructor call:

String name = new String("Alice");
Rectangle r = new Rectangle(5, 3);

For String, Java also allows the shortcut String name = "Alice"; because strings are so common.

References vs objects

The variable name does not hold the object itself — it holds a reference (an address) pointing to the object in memory. Two variables can refer to the same object:

Rectangle a = new Rectangle(5, 3);
Rectangle b = a;   // b points to the SAME object as a

Changing the object through b also affects a, because they reference the same object.

The null reference

null means "this reference points to no object." Calling a method on a null reference throws a NullPointerException:

String s = null;
int len = s.length();   // NullPointerException at runtime

Primitives vs objects

Primitives like int, double, and boolean store actual values. Objects are accessed through references. This distinction matters for assignment, comparison, and parameter passing.

03
Key Vocabulary

Words you must recognize instantly.

These terms appear in nearly every AP CSA question on objects.

Vocabulary
  • Class — a blueprint that defines the data and behavior of objects.
  • Object — a specific instance created from a class.
  • Instance — another word for one object built from a class.
  • Reference — a variable that points to an object in memory.
  • Instantiation — the act of creating an object using new.
  • Constructor — a special method that initializes an object when it is created.
  • null — a reference that points to no object.
  • NullPointerException — runtime error from calling a method on a null reference.
04
AP Exam Focus

How objects appear on the AP exam.

References, aliasing, and null behavior dominate the questions.

Exam Focus

MCQ patterns to expect:

  • Aliasing. Two variables refer to the same object; changing through one affects the other.
  • == vs .equals(). == compares references; .equals() compares object contents.
  • Null behavior. Recognize when a method call will throw NullPointerException.
  • Object vs primitive parameters. When you pass an object to a method, you pass the reference — so the method can mutate the object.

FRQ tip: when creating an object, always use the correct constructor signature. The College Board penalizes calls to constructors that don't exist in the provided class.

05
Worked Example

Trace reference assignment and aliasing.

The key is to track which references point to which objects.

Worked Example AP-style reasoning

Problem. Assume Point has fields x and y with getters and a method setX(int). What is printed?

Point p = new Point(2, 5);
Point q = p;
q.setX(10);
System.out.println(p.getX());

Step 1. new Point(2, 5) creates one object. p stores a reference to it.

Step 2. Point q = p; copies the reference, not the object. Now p and q point to the same object.

Step 3. q.setX(10) modifies the shared object's x field.

Step 4. p.getX() reads the same object's x, which is now 10.

Answer. The program prints 10.

Why this matters. Object assignment never makes a copy — it copies the reference. Recognizing this is the difference between a 3 and a 5 on FRQ tracing problems.

06
Common Mistakes

Errors students make with objects.

Most of these come from confusing references with values.

Watch Out
  • Comparing objects with ==. This compares references, not contents. Use .equals() for Strings and other object content checks.
  • Forgetting new. Without new, you have a reference variable but no object — calling methods on it gives a NullPointerException.
  • Calling methods on null. Always check whether a reference might be null before calling methods on it.
  • Assuming assignment copies the object. b = a; copies the reference, so both names point to the same object.
  • Confusing class names with object names. The class is the blueprint; the object is an instance of it. You can have many objects from one class.
07
Reference Table

Objects, references, and primitives.

Quick comparison of how each behaves in Java.

Objects Reference

AP Quick Reference
Concept Meaning AP Exam Tip
Class Blueprint for objects Defines fields and methods.
Object Instance built from a class Created with new.
Reference variable Stores the address of an object Multiple references can point to the same object.
Primitive variable Stores an actual value int, double, boolean, etc.
== on objects Compares references True only if same object in memory.
.equals() Compares contents Standard for String equality.
null Reference to no object Calling a method on it throws an exception.
08
Practice Tip

How to truly understand objects.

Build a mental model of memory and you'll never miss a reference question again.

Practice Strategy

Use the three practice tools below this lesson in order:

  • MCQ Practice — for every problem, sketch boxes for objects and arrows for references. Update the diagram as each line runs.
  • Java Lab — instantiate objects from provided classes, store them in references, and call methods. Confirm aliasing behavior by mutating through one reference and reading from another.
  • FRQ Practice — practise writing code that creates objects with constructors and uses their methods. Use the exact constructor signature shown in the FRQ.

If you can draw the memory diagram, you can answer any object question on the exam.

09
Section · 09

Practice — attempt these now.

AP-style assessments aligned to this lesson. Time them.

Topic Quiz 30 min 27 marks Pending

AP CSA Topic Practice: Objects

AP-style topic practice assessment

Start
FRQ Practice 30 min 18 marks Pending

AP CSA Unit 01 Topic 01 Objects FRQ Practice

AP-style topic practice assessment

Start