Say what the Java gives, then flip the card; pick a unit, or print it as cards.
AP Computer Science A Study Guide
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 / 53 Both are int, so the decimals are dropped.
17 % 52 What is left after 3 fives.
17 / 5.03.4 One double makes the whole quotient a double.
4 % 94 9 goes into 4 no times, so all of 4 is left.
3 / 4 * 80 Left to right: 3 / 4 is 0 first.
8 * 3 / 46 Left to right: 24 / 4.
Show all 60
7 + 3 * 2 % 49 * and % first, left to right: 6 % 4 is 2.
(double) 9 / 24.5 The cast acts on 9 before the division.
(double) (9 / 2)4.0 The int division is done first.
(int) 7.97 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 intInteger.MIN_VALUE to Integer.MAX_VALUE 4 bytes: −2,147,483,648 to 2,147,483,647.
Integer.MAX_VALUE + 1Integer.MIN_VALUE Integer overflow: a wrong value and no error.
0.1 + 0.2 == 0.3false Round-off error: a double is stored only as nearly as its bits allow.
The three primitive types of the courseint, 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 errorBreaks a rule of the language The compiler reports it before the program runs.
Logic errorIt runs, with a wrong result Testing with known data can show it.
Run-time errorStrikes 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 methodsSame name, different signatures The argument types decide which one is called.
Parameter; argumentIn the header; in the call The parameter is the variable, the argument its value.
Call by valueThe parameter gets a copy For an object the copy is of the reference.
int r = printAll(); when printAll is voidDoes not compile A void method gives nothing back to store.
Precondition; postconditionMust 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() * 60 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 ss.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 objectsSame 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 == btrue 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 xDoes not compile = stores; == compares.
1 <= x <= 10 in JavaDoes not compile Write x >= 1 && x <= 10.
Show all 60
x is from 1 to 10, both includedx >= 1 && x <= 10
x is outside 1 to 10x < 1 || x > 10
true || false && falsetrue && goes before ||.
a and b are booleans: exactly one of them is truea != 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 0false, with no exception The division never runs.
10 / x > 1 && x != 0, when x is 0ArithmeticException 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 is5 Both ifs run: 11, then 5.
if (n > 5) n = 1; else if (n > 0) n = 2; from 8, n is1 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 startIts body never runs The test comes before every pass.
Infinite loopIts test never turns false Nothing in the body moves toward the end.
Off-by-one errorOne 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 < bb - a
Passes of i = a; i <= b; i++ when a < bb - a + 1
The order of the parts of a for loopStart 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 as27 1, 3, 9, 27.
int n = 25; while (n > 3) n -= 4; n ends as1 25, 21, 17, 13, 9, 5, 1.
s is 0; for (int i = 1; i <= 4; i++) s += i; s ends as10 1 + 2 + 3 + 4.
p is 1; for (int i = 2; i < 6; i++) p *= i; p ends as120 2 * 3 * 4 * 5.
s is 0; for (int i = 5; i > 0; i -= 2) s += i; s ends as9 5 + 3 + 1.
return inside a loopLeaves the method at once The loop does not finish.
int n is evenn % 2 == 0
int n can be divided by d with nothing leftn % d == 0
Last digit of a positive int nn % 10
A positive int n without its last digitn / 10
Loop test for taking a positive int apart, digit by digitn > 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 maximumThe first value Starting at 0 fails if all are negative.
Test of a loop over each character of si < s.length() i starts at 0.
Test of a loop over each pair of neighbors in si < s.length() - 1 substring(i, i + 2) must not run past the end.
Test of a loop over each piece of k letters in si <= s.length() - k The last piece starts at length - k.
String r = ""; reverse s: body of the forward loopr = 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 runs10 times 1 + 2 + 3 + 4.
i < 5 from 0, inner j < i from 0: inner body runs10 times 0 + 1 + 2 + 3 + 4.
Both loops of a nested pair run n passes: inner bodyn * n times
Statement execution countHow 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.
privateSeen only inside its own class
publicOpen to code in other classes
EncapsulationData hidden inside its class private variables, reached by public methods.
Instance variableEach object has its own copy
Class (static) variableOne copy that all objects share
State of an objectIts attributes and their values now
Show all 37
Name and return type of a constructorThe 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 double0; 0.0
Default value of a boolean; of a Stringfalse; null Any reference type starts as null.
A local variable with no value yet, usedDoes not compile Instance and class variables get defaults; a local one does not.
Accessor methodReturns the value of a variable Not void: a getter.
Mutator methodChanges an instance or class variable Often void: a setter.
Code right after a return statementNever 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 intStays as it was Only the copy changed.
A method changes an object through its parameterThe caller sees the change Both references lead to the same object.
A method sets its object parameter to a new objectThe caller’s variable stays Only the copy of the reference moved.
A swap method with two int parametersSwaps 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 storeA 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 variableLives only in the block that declares it Parameters count as local variables.
Local and instance variable share a nameThe name means the local one this.name reaches the instance variable.
x = x; in a constructor with a parameter xThe instance variable is not set Write this.x = x;
thisThe 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 directlyDoes not compile It needs an object passed to it.
static int count; the constructor adds 1; 3 objects madecount is 3 One shared copy.
finalIts value cannot be changed
public static MAX of class Game, read from outsideGame.MAX
has-a relationshipAn object and its instance variables A Car has a wheel count.
Procedural abstractionUse it by what it does, not how
Data abstractionData 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 reliabilityWorks 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 biasRepeated 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 ta.length; s.length(); t.size() Only the array has no parentheses.
Last element of an array aa[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] is2 Index 2.
int[] a = {3, 0, 1, 7}; a[a[2]] is0 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 endint i = a.length - 1; i >= 0; i-- Not i > 0: that misses index 0.
Are all elements positive? Return inside the loopfalse, at the first that is not return true goes after the loop.
Is any element positive? Return inside the looptrue, at the first that is return false goes after the loop.
Looking for duplicates: inner loop starts atj = i + 1 So no element meets itself.
Shift left by one: a loop from 0 setsa[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 ati < a.length / 2 Going on would swap all back.
Classes for reading a text fileFile and Scanner Import java.io and java.util.
Scanner in = new Scanner(new File("a.txt")); header needsthrows IOException Or the method does not compile.
Loop test for reading a file to its endin.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 intInputMismatchException
What to call when you are done with a filein.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") + 143
Double.parseDouble("2") * 24.0
Autoboxingint to Integer, double to Double Done by the compiler.
UnboxingInteger to int, Double to double
ArrayList<int>Does not compile Use ArrayList<Integer>: it holds objects.
Import for ArrayListjava.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 out6 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 tt.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 skippingGo from the last index down Or leave i alone after a removal.
Adding or removing inside an enhanced for loopAn exception may stop the program ConcurrentModificationException.
m(n): if n > 0, print n, then call m(n - 1). m(3) prints3 2 1
m(n): if n > 0, call m(n - 1), then print n. m(3) prints1 2 3 The prints wait for the calls to come back.
p(s): "" if s is "", else p(s.substring(1)) + first letters 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.
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.