AP CSA - Advanced Placement Computer Science A Practice Test

AP Computer Science A is a challenging course, and the exam covers a lot of ground in Java programming. This AP CSA cheat sheet pulls together the most tested concepts, syntax patterns, and methods you need to have internalized before exam day. It's not a replacement for working through practice problems—you need reps to make these stick—but it gives you a fast-reference framework for everything the College Board tests.

Keep in mind: you can't bring this into the actual exam. The AP CSA exam gives you the AP Java Quick Reference document, which contains a subset of Java methods and class definitions. Know what's in that document (it's on the College Board website—download it and study it separately), and use this guide to internalize the concepts behind the code.

Java Fundamentals: Syntax You Must Know Cold

Primitive types tested in AP CSA: int, double, boolean. That's it—the AP exam focuses on these three. String is also heavily tested but is a class, not a primitive.

Variable declaration and initialization:

int x = 5;
double d = 3.14;
boolean flag = true;
String s = "hello";

Integer division gotcha: When you divide two ints in Java, the result is an int—the decimal is truncated, not rounded. 7 / 2 = 3, not 3.5. This trips up AP exam candidates constantly. To get a double result from integer division, cast one operand: (double) 7 / 2 = 3.5.

String concatenation with numbers: "value: " + 5 produces "value: 5". But 1 + 2 + " items" produces "3 items" because the + operator evaluates left to right, adding the integers first. Order matters.

Casting: int x = (int) 9.7; gives x = 9 (truncated). Casting from double to int always truncates toward zero, never rounds.

String Methods (Heavily Tested)

These are the String methods in the AP Java Quick Reference. Know every one:

s.length() — returns the number of characters. Remember: no parentheses on array .length, but you DO use parentheses on String .length().

s.substring(from, to) — returns the substring from index from (inclusive) to to (exclusive). "hello".substring(1, 3) returns "el". The from index character IS included; the to index character is NOT.

s.substring(from) — returns everything from index from to end of string.

s.indexOf(str) — returns the index of the first occurrence of str within s. Returns -1 if not found.

s.equals(other) — compares string content. NEVER use == to compare String content in Java—that compares references, not values. This is one of the most common bugs the AP exam tests.

s.compareTo(other) — returns negative if s comes before other alphabetically, 0 if equal, positive if s comes after. Used for sorting and comparison logic.

s.toLowerCase() / s.toUpperCase() — returns new String with case changed. Doesn't modify original (Strings are immutable).

Arrays: Critical Patterns

Arrays are heavily tested. Know these patterns cold:

Declaration and initialization:
int[] arr = new int[5]; — creates array of 5 ints, all initialized to 0.
int[] arr = {1, 2, 3, 4, 5}; — creates and initializes with literal values.
Array indices run from 0 to arr.length - 1. Accessing index arr.length throws ArrayIndexOutOfBoundsException.

Standard traversal:
for (int i = 0; i < arr.length; i++) { ... }

Enhanced for loop (for-each):
for (int val : arr) { ... }
Use this when you need to read values but don't need the index. Can't use it when you need to modify array elements—you need the index for that.

2D arrays:
int[][] grid = new int[rows][cols];
Access: grid[row][col]
Traverse: nested for loops, outer loop over rows, inner over columns.
grid.length gives number of rows. grid[0].length gives number of columns.

Common array algorithms: Finding max/min, linear search, computing sum/average. Know how to write these from scratch—the AP exam regularly tests them in free-response questions.

ArrayList Methods

The AP exam tests ArrayList extensively. From the Java Quick Reference:

list.size() — returns the number of elements (not a fixed length like arrays).

list.add(element) — appends to end of list.

list.add(index, element) — inserts at specified index, shifts elements right.

list.get(index) — returns element at index.

list.set(index, element) — replaces element at index, returns old element.

list.remove(index) — removes element at index, shifts elements left, returns removed element.

ArrayList iteration trap: When removing elements during iteration using a regular for loop (index-based), always iterate backward or adjust the index after removal. Removing elements while iterating forward causes you to skip elements. This is a classic AP free-response trap.

ArrayList stores objects, not primitives. Use Integer instead of int, Double instead of double. Java autoboxing converts automatically in most cases, but understand when this matters.

Start Free Practice Test

Object-Oriented Programming Concepts

OOP is the conceptual backbone of AP CSA. You need to understand these well enough to both read and write code:

Classes and objects: A class is a blueprint; an object is an instance of that class. Dog myDog = new Dog("Rex"); creates a Dog object named myDog.

Constructors: Special method with the same name as the class, no return type. Called when you use new to create an object. If you don't define a constructor, Java provides a default no-arg constructor.

this keyword: Refers to the current object. Used to resolve ambiguity when instance variables and parameters have the same name: this.name = name;

Encapsulation: Private instance variables, public getter/setter methods. The AP exam tests whether you understand why we do this—to control access and protect data integrity.

Inheritance: public class Dog extends Animal { ... }. Dog inherits all non-private methods and fields from Animal. Use super() to call the parent class constructor. Use super.methodName() to call an overridden parent method.

Polymorphism: An Animal reference can hold a Dog object if Dog extends Animal. The actual method called at runtime depends on the object type, not the reference type (dynamic dispatch). This is tested in multiple forms on the AP exam.

Method overriding: Subclass provides its own implementation of a method defined in the superclass. The signatures must match exactly. The @Override annotation is optional but good practice.

Abstract classes: Can't be instantiated directly. Define abstract methods that subclasses must implement. Know the syntax: public abstract class Shape { public abstract double area(); }

Interfaces: Defines a contract—methods that implementing classes must provide. public class Circle extends Shape implements Drawable { ... }

Recursion: Key Patterns

Recursion questions appear in both multiple choice and free response. Know these patterns:

Base case and recursive case: Every recursive method needs at least one base case (direct answer, no further recursion) and at least one recursive case (calls itself with a simpler input). Missing base case = infinite recursion = stack overflow.

Classic recursion example — factorial:
public static int factorial(int n) {
  if (n == 0) return 1; // base case
  return n * factorial(n - 1); // recursive case
}

Tracing recursion: The AP exam often asks you to trace a recursive method—determine what it returns for a given input. Practice by writing out the call stack step by step. Each call waits for the next to return before completing.

Recursive vs. iterative: Any recursive solution can be rewritten iteratively. For the AP exam, you need to be able to read and write both forms and understand what each is doing.

Sorting Algorithms

The AP CSA exam tests two sorting algorithms conceptually:

Selection sort: Find the smallest element in the unsorted portion and swap it to its correct position. Repeat. O(n²) time complexity. Does n-1 passes over data.

Insertion sort: Take each element and insert it into the correct position in the sorted portion to its left. O(n²) worst case, but efficient for nearly-sorted data.

You don't need to implement these from scratch perfectly in free response (though you might be asked to trace them or modify them). You do need to understand how they work, which one makes more swaps, and how many passes each makes.

Common AP Exam Mistakes

A few patterns that cost points repeatedly:

Using == to compare Strings instead of .equals(). Forgetting that String.substring(from, to) is exclusive at the to index. Off-by-one errors in array loops—always double-check your loop bounds. Integer division truncation surprises. Modifying an ArrayList while iterating forward with an index and skipping elements. Returning from inside a loop when you meant to continue the loop. Confusing .length (no parentheses, used for arrays) with .length() (parentheses, used for Strings) with .size() (parentheses, used for ArrayLists).

Make yourself a practice problem where you trace through code with each of these pitfalls. The more times you manually trace through code containing these patterns, the less likely you are to miss them under exam pressure.

What is the AP CSA cheat sheet based on?

This guide is based on the College Board AP Computer Science A Course and Exam Description, which defines the testable Java subset for the exam. The AP exam provides an official Java Quick Reference document during the test—study that separately, since it defines exactly what built-in methods and class definitions you can reference.

How many questions are on the AP CSA exam?

The AP CSA exam has two sections: 40 multiple-choice questions (90 minutes) and 4 free-response questions (90 minutes). Total time is 3 hours. Multiple choice is machine-scored; free response is scored by trained graders using detailed rubrics.

What Java topics are on the AP CSA exam?

The AP CSA exam covers primitive types, String methods, one-dimensional and two-dimensional arrays, ArrayLists, writing and calling methods, object-oriented programming (classes, inheritance, polymorphism), recursion, and sorting/searching algorithms. The College Board's Course and Exam Description lists the complete scope.

Do I get a reference sheet for AP CSA?

Yes. The College Board provides the AP Java Quick Reference document during the exam. It contains key class and method definitions for classes in the AP Java subset, including String, Integer, Double, Math, Object, ArrayList, and others. Download it from the College Board website and study it before the exam so you know exactly what's there.

What score do I need on AP CSA to get college credit?

Most colleges grant credit for a score of 3, 4, or 5. Some more selective programs require a 4 or 5 for credit or placement out of introductory CS courses. Check the specific credit policies of colleges you're applying to—policies vary significantly by school and by score threshold.

What's the hardest part of the AP CSA exam?

Most students find the free-response questions hardest, particularly the ones requiring writing methods from scratch or extending existing code. Recursion tracing in multiple choice is also consistently challenging. The time pressure on free response is real—4 questions in 90 minutes means about 22 minutes per question, including reading, planning, and writing.

How to Use This Guide Effectively

Reading a cheat sheet is not the same as knowing the material. Use this as a quick-reference companion to practice, not as a substitute for it. The AP CSA free-response questions require you to write actual Java code that compiles and runs correctly—that's a skill you build through repetition, not through reading.

After reviewing each section of this guide, close it and try to write the relevant code patterns from memory. Can you write a correct for-each loop traversal without looking? Can you write a recursive factorial method? Can you implement a selection sort? If you can produce these patterns fluently without reference, you're genuinely prepared. If you can only recognize them when you see them, you need more practice.

Use College Board's publicly released free-response questions from prior years—they're on the AP Central website. Go through at least the last three to five years of FRQs under timed conditions. Review the scoring guidelines afterward and understand why each point was or wasn't awarded. This is the most direct preparation for the exam's format and difficulty.

You've got the conceptual map now. The work is in the practice.

▶ Start Quiz