• 240 cards
  • Checked November 2026

AP Computer Science A Study Guide

Say what the Java gives, then flip the card; pick a unit, or print it as cards.

int a = 3; int b = a; a = 9; what does b hold?

Card 1 of 60 · Unit 1: Objects and methods

More options

Unit

Every AP Computer Science A card, by unit

Unit 1: Objects and methods

Numbered statements of this unit in the College Board’s Course and Exam Description of 2025 and the Java SE 17 documentation, read November 30, 2026. Code was run on Java 17.

  • 17 / 5 3 Both are int, so the decimals are dropped.
  • 17 % 5 2 What is left after 3 fives.
  • 17 / 5.0 3.4 One double makes the whole quotient a double.
  • 4 % 9 4 9 goes into 4 no times, so all of 4 is left.
  • 3 / 4 * 8 0 Left to right: 3 / 4 is 0 first.
  • 8 * 3 / 4 6 Left to right: 24 / 4.
Show all 60
  • 7 + 3 * 2 % 4 9 * and % first, left to right: 6 % 4 is 2.
  • (double) 9 / 2 4.5 The cast acts on 9 before the division.
  • (double) (9 / 2) 4.0 The int division is done first.
  • (int) 7.9 7 A cast cuts, it does not round.
  • (int) (2.6 + 0.5) 3 The course’s way to round a number that is not negative.
  • Round a negative double x to the nearest int (int) (x - 0.5) (int) (-3.7 - 0.5) is -4.
  • int x = 5 / 2.0; Does not compile A double does not fit an int without a cast.
  • double d = 5 / 2; what does d hold? 2.0 The int 2 is widened after the division.
  • int k = 14; k /= 4; what does k hold? 3 k = k / 4, with int division.
  • int n = 6; n *= 2 + 1; what does n hold? 18 The right side is worked out first: 6 * 3.
  • int a = 3; int b = a; a = 9; what does b hold? 3 b took a copy of the value, not a link to a.
  • int x = 8 / 0; ArithmeticException It compiles and stops at run time.
  • Range of an int Integer.MIN_VALUE to Integer.MAX_VALUE 4 bytes: −2,147,483,648 to 2,147,483,647.
  • Integer.MAX_VALUE + 1 Integer.MIN_VALUE Integer overflow: a wrong value and no error.
  • 0.1 + 0.2 == 0.3 false Round-off error: a double is stored only as nearly as its bits allow.
  • The three primitive types of the course int, double, boolean Everything else, String too, is a reference type.
  • What does print("a\nb") show? a, and b on the next line \n is the newline escape.
  • How do you put a " inside a string literal? \" A backslash itself is written \\.
  • 1 + 2 + "3" "33" Numbers add until a string comes: 3, then "33".
  • "1" + 2 + 3 "123" Once a string stands on the left, + joins.
  • Syntax error Breaks a rule of the language The compiler reports it before the program runs.
  • Logic error It runs, with a wrong result Testing with known data can show it.
  • Run-time error Strikes while the program runs An exception is one kind: the compiler did not see it.
  • What makes up a method signature? Its name and ordered parameter types Not the return type.
  • Overloaded methods Same name, different signatures The argument types decide which one is called.
  • Parameter; argument In the header; in the call The parameter is the variable, the argument its value.
  • Call by value The parameter gets a copy For an object the copy is of the reference.
  • int r = printAll(); when printAll is void Does not compile A void method gives nothing back to store.
  • Precondition; postcondition Must hold before; holds after The method is not expected to check the first.
  • How is a class (static) method called? ClassName.method(...) Inside its own class the name can be left out.
  • String s = null; s.length() NullPointerException There is no object to call the method on.
  • Every Java class is a subclass of which class? Object Which is why every object has toString and equals.
  • Math.abs(-4) 4 An int in, an int out; -2.5 gives 2.5.
  • Math.pow(2, 3) 8.0 pow always returns a double.
  • int p = Math.pow(2, 3); Does not compile Cast it: (int) Math.pow(2, 3) is 8.
  • Math.sqrt(16) 4.0 A double, even for a perfect square.
  • Math.random() gives which values? From 0.0 up to, but not including, 1.0 A double.
  • (int) (Math.random() * 10) A random int from 0 to 9 10 itself cannot come.
  • A random int from 1 to 6 (int) (Math.random() * 6) + 1 How many values, then the lowest one.
  • A random int from a to b, both included (int) (Math.random() * (b - a + 1)) + a There are b - a + 1 values.
  • (int) Math.random() * 6 0 The cast cuts the random number to 0 before the product.
  • "computer".length() 8 Indexes run from 0 to 7.
  • "computer".substring(0, 4) "comp" From index 0 up to, not including, 4.
  • "computer".substring(3) "puter" From index 3 to the end.
  • "computer".substring(8) "" (the empty string) An index equal to the length is still allowed here.
  • "computer".substring(9) An exception: index out of range StringIndexOutOfBoundsException.
  • s.substring(i, i + 1) The one character at index i As a String; char is not in the course.
  • The last character of s s.substring(s.length() - 1) The last index is the length minus 1.
  • "banana".indexOf("an") 1 The first place only.
  • "banana".indexOf("x") -1 The sign for not found.
  • "cat".equals("Cat") false Capitals count.
  • "ant".compareTo("bee") A negative int ant comes first in the alphabet.
  • String s = "tap"; s.substring(1); what is s now? "tap" A String cannot change. Store the result to keep it.
  • String s = "ab"; s += 1; what is s now? "ab1" += joins and makes a new String.

Unit 2: Selection and iteration

Numbered statements of this unit in the College Board’s Course and Exam Description of 2025 and the Java SE 17 documentation, read November 30, 2026. Code was run on Java 17.

  • == on two ints; == on two objects Same value; same object On objects it compares the references.
  • new String("hi") == new String("hi") false Two objects. .equals gives true.
  • Dog b = a; then a == b true Two variables, one object: aliases.
  • How do you test that s refers to no object? s == null s.equals(null) would fail if s is null.
  • if (x = 5) with an int x Does not compile = stores; == compares.
  • 1 <= x <= 10 in Java Does not compile Write x >= 1 && x <= 10.
Show all 60
  • x is from 1 to 10, both included x >= 1 && x <= 10
  • x is outside 1 to 10 x < 1 || x > 10
  • true || false && false true && goes before ||.
  • a and b are booleans: exactly one of them is true a != b Or a && !b || !a && b.
  • !(a && b) !a || !b De Morgan: the sign inside flips too.
  • !(a || b) !a && !b De Morgan.
  • !(x < 5) x >= 5 The opposite of < is >=.
  • !(x >= 3 && x < 8) x < 3 || x >= 8 Turn each part round, and && into ||.
  • Short-circuit: when is b skipped in a && b? When a is false The result is already known.
  • Short-circuit: when is b skipped in a || b? When a is true The result is already known.
  • x != 0 && 10 / x > 1, when x is 0 false, with no exception The division never runs.
  • 10 / x > 1 && x != 0, when x is 0 ArithmeticException The check comes too late.
  • if, else if, else: how many branches run? One The first true one; else if none is. Without else, perhaps none.
  • Three ifs in a row, no else: how many may run? Any number, 0 to 3 Each is tested on its own.
  • int n = 7; if (n > 5) n += 4; if (n > 10) n -= 6; n is 5 Both ifs run: 11, then 5.
  • if (n > 5) n = 1; else if (n > 0) n = 2; from 8, n is 1 The else if is not looked at again.
  • No braces: how many statements belong to an if? One Indenting the next line does not add it.
  • while loop whose test is false at the start Its body never runs The test comes before every pass.
  • Infinite loop Its test never turns false Nothing in the body moves toward the end.
  • Off-by-one error One pass too many or too few < where <= was meant, or the other way round.
  • for (int i = 0; i < 10; i++): how many passes? 10 i is 0 to 9.
  • for (int i = 0; i <= 10; i++): how many passes? 11 i is 0 to 10.
  • for (int i = 1; i < 10; i++): how many passes? 9 i is 1 to 9.
  • for (int i = 2; i < 9; i += 3): how many passes? 3 i is 2, 5, 8.
  • for (int i = 10; i > 0; i -= 2): how many passes? 5 i is 10, 8, 6, 4, 2.
  • for (int i = 5; i < 5; i++): how many passes? 0 The test is false at once.
  • for (int i = 8; i > 0; i /= 2): how many passes? 4 i is 8, 4, 2, 1; then 0.
  • for (int i = 1; i < 50; i *= 2): how many passes? 6 i is 1, 2, 4, 8, 16, 32.
  • Passes of i = a; i < b; i++ when a < b b - a
  • Passes of i = a; i <= b; i++ when a < b b - a + 1
  • The order of the parts of a for loop Start once; then test, body, update Test, body and update repeat.
  • Where does the update of a for loop go in a while? At the end of the body The start goes above the loop.
  • for (int i = 0; ...): can you use i after the loop? No, it is out of scope Declare it above the loop to keep it.
  • int i = 1; while (i < 20) i *= 3; i ends as 27 1, 3, 9, 27.
  • int n = 25; while (n > 3) n -= 4; n ends as 1 25, 21, 17, 13, 9, 5, 1.
  • s is 0; for (int i = 1; i <= 4; i++) s += i; s ends as 10 1 + 2 + 3 + 4.
  • p is 1; for (int i = 2; i < 6; i++) p *= i; p ends as 120 2 * 3 * 4 * 5.
  • s is 0; for (int i = 5; i > 0; i -= 2) s += i; s ends as 9 5 + 3 + 1.
  • return inside a loop Leaves the method at once The loop does not finish.
  • int n is even n % 2 == 0
  • int n can be divided by d with nothing left n % d == 0
  • Last digit of a positive int n n % 10
  • A positive int n without its last digit n / 10
  • Loop test for taking a positive int apart, digit by digit n > 0 n % 10 is the digit, then n /= 10.
  • sum and count are ints: their exact average (double) sum / count sum / count would drop the decimals.
  • Safe starting value when you look for a maximum The first value Starting at 0 fails if all are negative.
  • Test of a loop over each character of s i < s.length() i starts at 0.
  • Test of a loop over each pair of neighbors in s i < s.length() - 1 substring(i, i + 2) must not run past the end.
  • Test of a loop over each piece of k letters in s i <= s.length() - k The last piece starts at length - k.
  • String r = ""; reverse s: body of the forward loop r = s.substring(i, i + 1) + r; New letter in front. r + letter would copy s.
  • i = 0 to 3, inner j = 0 to i: inner body runs 10 times 1 + 2 + 3 + 4.
  • i < 5 from 0, inner j < i from 0: inner body runs 10 times 0 + 1 + 2 + 3 + 4.
  • Both loops of a nested pair run n passes: inner body n * n times
  • Statement execution count How often a statement runs Found by tracing the loops.

Unit 3: Class creation

Numbered statements of this unit in the College Board’s Course and Exam Description of 2025 and the Java SE 17 documentation, read November 30, 2026. Code was run on Java 17.

  • private Seen only inside its own class
  • public Open to code in other classes
  • Encapsulation Data hidden inside its class private variables, reached by public methods.
  • Instance variable Each object has its own copy
  • Class (static) variable One copy that all objects share
  • State of an object Its attributes and their values now
Show all 37
  • Name and return type of a constructor The class’s name; no return type
  • public void Dog() in class Dog: is it a constructor? No, a method The word void makes it one.
  • When does Java supply a no-parameter constructor? When you write none Write any constructor and it is gone.
  • Default value of an int; of a double 0; 0.0
  • Default value of a boolean; of a String false; null Any reference type starts as null.
  • A local variable with no value yet, used Does not compile Instance and class variables get defaults; a local one does not.
  • Accessor method Returns the value of a variable Not void: a getter.
  • Mutator method Changes an instance or class variable Often void: a setter.
  • Code right after a return statement Never runs javac reports it as unreachable.
  • int f(int n) { if (n > 0) return 1; } Does not compile Some calls would return nothing.
  • A method changes its int parameter: the caller’s int Stays as it was Only the copy changed.
  • A method changes an object through its parameter The caller sees the change Both references lead to the same object.
  • A method sets its object parameter to a new object The caller’s variable stays Only the copy of the reference moved.
  • A swap method with two int parameters Swaps nothing for the caller It moves the two copies.
  • Returning an object: what is handed back? The reference, not a copy
  • Constructor gets a mutable object: what to store A copy of it Else outside code could change your object.
  • Can a method read other.x when x is private? Yes, if other is of the same class
  • Local variable Lives only in the block that declares it Parameters count as local variables.
  • Local and instance variable share a name The name means the local one this.name reaches the instance variable.
  • x = x; in a constructor with a parameter x The instance variable is not set Write this.x = x;
  • this The object whose method is running It can also be passed as an argument.
  • Can a static method use this? No It belongs to the class, not to an object.
  • A static method uses an instance variable directly Does not compile It needs an object passed to it.
  • static int count; the constructor adds 1; 3 objects made count is 3 One shared copy.
  • final Its value cannot be changed
  • public static MAX of class Game, read from outside Game.MAX
  • has-a relationship An object and its instance variables A Car has a wheel count.
  • Procedural abstraction Use it by what it does, not how
  • Data abstraction Data with a name, details hidden
  • What may you change without telling a method’s users? Its inside As long as signature and effect stay.
  • System reliability Works as expected, without failure Test under many conditions.

Unit 4: Data collections

Numbered statements of this unit in the College Board’s Course and Exam Description of 2025 and the Java SE 17 documentation, read November 30, 2026. Code was run on Java 17.

  • Algorithmic bias Repeated errors unfair to one group
  • Why may a good data set give a wrong answer? It was gathered for another question Or it is incomplete, inaccurate or biased.
  • int[] a = new int[5]; what is a[0]? 0
  • String[] w = new String[4]; what is w[2]? null No strings are made yet.
  • Length of an array a; of a String s; of an ArrayList t a.length; s.length(); t.size() Only the array has no parentheses.
  • Last element of an array a a[a.length - 1]
Show all 83
  • a[a.length] An exception: index out of range ArrayIndexOutOfBoundsException.
  • Can an array grow after it is made? No, its length is fixed
  • int[] a = {5, 8, 2, 9}; a[a.length / 2] is 2 Index 2.
  • int[] a = {3, 0, 1, 7}; a[a[2]] is 0 a[2] is 1, so it is a[1].
  • int[] b = a; b[0] = 50; what is a[0]? 50 One array, two names.
  • for (int x : a) x = 0; what changes in a? Nothing x is a copy of each element.
  • for (Dog d : dogs) d.rename("Rex"); what changes? Each dog in the array The objects, not the references.
  • What does an enhanced for loop not give you? The index Use an indexed loop to set or compare places.
  • Loop test for neighbors a[i] and a[i + 1] i < a.length - 1
  • Header to visit an array from the end int i = a.length - 1; i >= 0; i-- Not i > 0: that misses index 0.
  • Are all elements positive? Return inside the loop false, at the first that is not return true goes after the loop.
  • Is any element positive? Return inside the loop true, at the first that is return false goes after the loop.
  • Looking for duplicates: inner loop starts at j = i + 1 So no element meets itself.
  • Shift left by one: a loop from 0 sets a[i] = a[i + 1] Stop at i < a.length - 1.
  • Shift right by one: where does the loop start? At the last index, going down From the front, the first value would spread.
  • {1, 2, 3, 4}; for i = 0 to 2: a[i + 1] = a[i]; {1, 1, 1, 1}
  • {1, 2, 3, 4}; for i = 1 to 3: a[i] += a[i - 1]; {1, 3, 6, 10} Running totals.
  • Reverse an array in place: the loop stops at i < a.length / 2 Going on would swap all back.
  • Classes for reading a text file File and Scanner Import java.io and java.util.
  • Scanner in = new Scanner(new File("a.txt")); header needs throws IOException Or the method does not compile.
  • Loop test for reading a file to its end in.hasNext() in is the Scanner.
  • next() or nextLine(): which reads one word? next() nextLine() takes the rest of the line.
  • nextInt() when the next item is not an int InputMismatchException
  • What to call when you are done with a file in.close() in is the Scanner.
  • "a,b,c".split(",") has which length? 3
  • "12-7".split("-")[1] "7" A String, not an int.
  • Integer.parseInt("42") + 1 43
  • Double.parseDouble("2") * 2 4.0
  • Autoboxing int to Integer, double to Double Done by the compiler.
  • Unboxing Integer to int, Double to double
  • ArrayList<int> Does not compile Use ArrayList<Integer>: it holds objects.
  • Import for ArrayList java.util.ArrayList
  • [A, B, C]: after add("X") [A, B, C, X] At the end. It returns true.
  • [A, B, C]: after add(1, "X") [A, X, B, C] The rest move right.
  • [A, B, C]: after set(1, "X") [A, X, C] The size stays 3.
  • [A, B, C]: what does set(1, "X") return? B The element it replaced.
  • [A, B, C]: after remove(0) [B, C] The rest move left.
  • [A, B, C]: what does remove(1) return? B The element taken out.
  • [5, 6, 7] of Integer: remove(1) takes out 6 1 is the index, not the value.
  • [A, B, C]: get(3) An exception: index out of range IndexOutOfBoundsException.
  • [A, B, C]: add(3, "X") [A, B, C, X] An index equal to size() is allowed here.
  • Last element of an ArrayList t t.get(t.size() - 1)
  • A forward loop with i++ removes every 2 from [2, 2, 5] [2, 5] After a removal the next one slides under i.
  • Removing in a loop without skipping Go from the last index down Or leave i alone after a removal.
  • Adding or removing inside an enhanced for loop An exception may stop the program ConcurrentModificationException.
  • m[a][b]: which index is the row? The first, a
  • int[][] m = {{1, 2, 3}, {4, 5, 6}}; m[1][2] is 6 Row 1, column 2.
  • Number of rows of m m.length
  • Number of columns of m m[0].length
  • m[1] alone Row 1, as a 1D array
  • Last element of m m[m.length - 1][m[0].length - 1]
  • Row-major order Across each row in turn Rows are the outer loop.
  • Column-major order Down each column in turn Columns are the outer loop.
  • {{1, 2}, {3, 4}, {5, 6}} in column-major order 1 3 5 2 4 6
  • for (___ row : m) over an int[][] m int[] The inner loop then takes int x : row.
  • Sum of column c: the loop runs over The rows: r < m.length It adds m[r][c].
  • Sum of row r: the loop runs over The columns: c < m[r].length It adds m[r][c].
  • Main diagonal of a square m m[i][i]
  • Linear search Check each element in order Works on unsorted data, from either end.
  • Binary search needs Sorted data
  • Each step of a binary search Drops half of what is left It looks at the middle element.
  • Binary search of 1,000 items: at most how many checks? 10 2 to the 10th is 1,024.
  • Selection sort Swap the smallest of the rest into place After k passes the first k are final.
  • Insertion sort Slide the next one into the sorted part After k passes the first k + 1 are sorted.
  • Merge sort Split to single items, merge in order Recursive.
  • {8, 3, 6, 1}: after pass 1 of selection sort {1, 3, 6, 8} 1 and 8 change places.
  • {8, 3, 6, 1}: after pass 1 of insertion sort {3, 8, 6, 1}
  • {8, 3, 6, 1}: after pass 2 of insertion sort {3, 6, 8, 1}
  • Base case Where a recursive method stops It makes no further call.
  • Do recursive calls share their local variables? No, each call has its own
  • f(n): 1 if n <= 1, else n * f(n - 1). f(5) is 120 5 * 4 * 3 * 2 * 1.
  • g(n): 0 if n is 0, else n % 10 + g(n / 10). g(407) is 11 It adds the digits.
  • h(n): 1 if n <= 1, else h(n - 1) + h(n - 2). h(5) is 8 1, 1, 2, 3, 5, 8.
  • m(n): if n > 0, print n, then call m(n - 1). m(3) prints 3 2 1
  • m(n): if n > 0, call m(n - 1), then print n. m(3) prints 1 2 3 The prints wait for the calls to come back.
  • p(s): "" if s is "", else p(s.substring(1)) + first letter s in reverse p("code") is "edoc".
  • What can always replace recursion? A loop, and the other way round

How this list was compiled: Cards written for this site in our own words, sorted by the four units of the College Board's AP Computer Science A Course and Exam Description, effective fall 2025 (apcentral.collegeboard.org), whose numbered statements and Java Quick Reference each card follows; the meaning of a method was checked in the Java SE 17 documentation (docs.oracle.com), and of a rule the statements do not spell out in the Java Language Specification (docs.oracle.com), all read November 30, 2026. Every line of code with a value was compiled and run on OpenJDK 17, and every line said not to compile was given to its compiler. No sample question, released question or AP Classroom item was used.

Checked against: apcentral.collegeboard.org, docs.oracle.com. Read November 30, 2026.

How it works

This AP Computer Science A study guide is 240 cards in our own words: what a piece of Java gives, with the rule behind it. It is unofficial and not affiliated with the College Board.

Read the full guide

Where the points are

Data Collections, Unit 4, carries 30–40% of the multiple-choice section. Selection and Iteration has 25–35%, Using Objects and Methods 15–25%, Class Creation 10–18%, by the course description. The deck holds 83, 60, 60 and 37 cards.

What the answers rest on

Each value a line of Java gives came from running it on Java 17, and what a card calls “Does not compile” was refused by the compiler.

Print it, or make a PDF

Pick a unit under the card, or All. Print makes double-sided cards; the fold-over print suits a one-sided printer.

  • For a loop, write down the first value, the last value and the step before you count.

Questions and answers

Is there an AP Computer Science A study guide PDF?

You make it here: choose a unit, press Print and pick Save as PDF as the printer. Unit 1 is 60 cards on 5 sheets; All is 240 on 20.

What should an AP Computer Science test study guide cover?

For the A exam, Java: casting and integer division, String and Math calls, conditions, loop counts, classes and scope, arrays, ArrayList, 2D arrays, files, searching, sorting and tracing recursion. Principles is another exam, in pseudocode.

Is inheritance on the AP Computer Science A exam?

Only the idea: a subclass extends a superclass, and every class comes from Object. Designing and writing inheritance is outside the course, by the description in force since fall 2025.

Do you get a reference sheet on the AP CSA exam?

Yes. The Java Quick Reference, in Bluebook, lists the String, Math, Integer, Double, ArrayList, File and Scanner calls. It does not say what they return on tricky input, such as substring(8) of an eight-letter word.

Do I have to write recursion for AP CSA?

No. You trace it: what a recursive call returns or prints. Writing recursive code is outside the exam. Unit 4 has six calls to trace.