AP CSA Cram Sheet
AP Computer Science A
Cram Sheet
The quick-reference guide for exam day. Every method, every trap, every pattern — built by a teacher whose students score 5s at 2x the national rate.
Unit 1: Using Objects & Methods
15–25%Primitive Types
| Type | Stores | Default | Watch Out |
|---|---|---|---|
int |
Whole numbers | 0 | Division truncates: 5/2 → 2
|
double |
Decimal numbers | 0.0 |
0.1 + 0.2 ≠0.3 (floating point) |
boolean |
true / false
|
false | Cannot use 0/1 as booleans in Java |
Operators & Assignment
-
Arithmetic:
+-*/%— integer/truncates,%gives remainder -
Compound:
+=-=*=/=%=and++-- -
Casting:
(int) 3.9→3(truncates, does NOT round);(double) 5→5.0 -
Integer overflow: exceeding
Integer.MAX_VALUEwraps to negative
Objects & Methods
- Reference types store memory addresses (Strings, objects)
-
Create objects:
ClassName obj = new ClassName(args); - Void methods perform action, return nothing
- Return methods give back a value you must use or store
- Method signature: name + parameter list (types and order matter)
String Methods (on Quick Reference)
| Method | Returns | Key Detail |
|---|---|---|
length() |
int | Number of characters |
substring(s, e) |
String | Index e is exclusive
|
substring(s) |
String | From s to end |
indexOf(str) |
int | Returns -1 if not found |
equals(other) |
boolean | Use this, NOT ==
|
compareTo(other) |
int | Negative, 0, or positive |
split(del) |
String[] | NEW: Splits around delimiter into array |
substring() return a new String — they never modify the original. Also, == compares references, not content. Always use .equals() for Strings.Wrapper Classes & Math
-
Integer, Double — needed for
ArrayList; autoboxing converts automatically -
Integer.parseInt(str)andDouble.parseDouble(str)convert Strings to numbers (on Quick Ref) -
Integer.MIN_VALUE/Integer.MAX_VALUE— useful for initializing min/max searches -
Math.abs(x),Math.pow(base, exp),Math.sqrt(x) -
Math.random()returns[0.0, 1.0)— includes 0.0, excludes 1.0 -
Random int in range:
(int)(Math.random() * range) + min
// Random int from 1 to 6 (inclusive)
int roll = (int)(Math.random() * 6) + 1;
Unit 2: Selection & Iteration
25–35%Boolean Expressions & Conditionals
-
Relational:
<><=>===!= -
Logical:
&&(AND)||(OR)!(NOT) -
Short-circuit:
&&stops on firstfalse;||stops on firsttrue - De Morgan’s Laws:
// These pairs are equivalent:
!(a && b) ↔ !a || !b
!(a || b) ↔ !a && !b
- if / if-else / else if: only one branch executes in a chain
- Dangling else: an
elsepairs with the nearest unmatchedif
Loops
| Loop | Syntax | Use When |
|---|---|---|
while |
while (cond) { ... } |
Unknown number of iterations |
for |
for (init; cond; update) |
Known count or index needed |
for-each |
for (Type x : arr) |
Read-only traversal (no index access) |
Essential Loop Patterns
// Accumulator (sum)
int sum = 0;
for (int val : arr) {
sum += val;
}
// Counter (count matches)
int count = 0;
for (int val : arr) {
if (val > 0) {
count++;
}
}
// Find max
int max = arr[0];
for (int val : arr) {
if (val > max) {
max = val;
}
}
String Traversal
for (int i = 0; i < str.length(); i++) {
String ch = str.substring(i, i + 1);
// process each character
}
0 to length - 1. Using <= instead of < causes ArrayIndexOutOfBoundsException.Nested Loops
- Outer loop runs m times, inner runs n times → body executes m × n times
- Used for: 2D traversal, pattern printing, comparing all pairs
Unit 3: Class Creation
10–18%Class Anatomy
public class Player {
private String name;
private int score;
public Player(String name, int score) {
this.name = name;
this.score = score;
}
// Accessor (getter)
public String getName() {
return name;
}
// Mutator (setter)
public void addPoints(int pts) {
score += pts;
}
// toString (on Quick Reference)
public String toString() {
return name + ": " + score;
}
}
Key Concepts
-
Encapsulation:
privateinstance variables +publicgetters/setters -
this: refers to the current object; disambiguates parameter vs. instance variable - Constructor overloading: multiple constructors with different parameter lists
-
Static members: belong to the class, not any instance. Called via
ClassName.method() -
Static methods cannot access instance variables (no
this) - Scope: local variables exist only inside their method/block
-
toString(): called automatically when object is printed or concatenated with a String -
equals(Object other): override to compare object content, not references
extends, super, and interfaces are NOT on this exam. Do not study sections 3.12–3.16.Unit 4: Data Collections
30–40%Arrays
-
Declaration:
int[] arr = new int[5];orint[] arr = {1, 2, 3}; - Fixed size — cannot grow or shrink after creation
-
Index:
0toarr.length - 1(note:.lengthhas NO parentheses) -
Default values:
0for int,0.0for double,falsefor boolean,nullfor objects
ArrayList
| Method | What It Does | Returns |
|---|---|---|
add(obj) |
Appends to end | boolean |
add(i, obj) |
Inserts at index, shifts right | void |
get(i) |
Returns element at index | E |
set(i, obj) |
Replaces element at index | old E |
remove(i) |
Removes at index, shifts left | removed E |
size() |
Number of elements | int |
- Wrapper types only:
ArrayList, notArrayList -
size()with parentheses vs.arr.lengthwithout
ArrayList during a for-each loop. Use a backward for loop when removing:for (int i = list.size() - 1; i >= 0; i--) {
if (list.get(i) < 0) {
list.remove(i);
}
}
Searching & Sorting
| Algorithm | How It Works | Requires | Efficiency |
|---|---|---|---|
| Linear Search | Check each element | Nothing | O(n) |
| Binary Search | Halve search space | Sorted data | O(log n) |
| Selection Sort | Find min, swap front | Nothing | O(n²) |
| Insertion Sort | Shift, insert in place | Nothing | O(n²) |
2D Arrays
int[][] grid = new int[3][4]; // 3 rows, 4 cols
grid.length // number of rows (3)
grid[0].length // number of cols (4)
// Row-major traversal (standard)
for (int r = 0; r < grid.length; r++)
for (int c = 0; c < grid[0].length; c++)
// process grid[r][c]
// Column-major traversal
for (int c = 0; c < grid[0].length; c++)
for (int r = 0; r < grid.length; r++)
// process grid[r][c]
File & Scanner (NEW for 2025–2026)
These classes are new to the exam and appear on the Quick Reference.
| Method | Returns | Key Detail |
|---|---|---|
new Scanner(new File(path)) |
Scanner | Opens file for reading |
nextInt() |
int | Throws InputMismatchException if wrong type |
nextDouble() |
double | Reads next decimal number |
nextBoolean() |
boolean | Reads next boolean value |
nextLine() |
String | Reads rest of line; can return empty after other next calls |
next() |
String | Reads next token (word) |
hasNext() |
boolean |
true if more data to read |
close() |
void | Always close when done reading |
// Reading a file line by line
Scanner input = new Scanner(new File("data.txt"));
while (input.hasNext()) {
String line = input.nextLine();
// process line
}
input.close();
nextLine() immediately after nextInt() returns an empty string because nextInt() leaves the newline in the buffer. Call nextLine() once to clear it first.Recursion Tracing (NEW for 2025–2026)
You will NOT write recursive methods — only trace them.
// Trace: what does mystery(4) return?
public static int mystery(int n) {
if (n <= 1) {
return 1;
}
return n * mystery(n - 1);
}
// mystery(4) → 4*mystery(3) → 4*3*mystery(2) → 4*3*2*mystery(1) → 24
FRQ Strategy Guide
| FRQ | Type | What They Test | Key Tip |
|---|---|---|---|
| #1 | Methods & Control | Conditionals, loops, calls | Follow method header exactly |
| #2 | Complete Class | Write class from scratch | ALL vars, constructors, methods |
| #3 | ArrayList | Traverse, modify ArrayLists | Watch removal index shift (backward) |
| #4 | 2D Array | Nested traversal | Check .length vs [0].length
|
Partial Credit Rules
- Write something for every part — even a comment showing your logic earns potential credit
- Use the exact method headers from the prompt (copy the signature)
- Do NOT rewrite provided methods — call them as given
- Declare variables with correct types even if your logic is incomplete
- Avoid
System.out.println()in FRQ solutions — return values instead
Java Quick Reference — Full 2026 Version (Provided on Exam)
String Class
int length()
String substring(int from, int to) // to is EXCLUSIVE
String substring(int from)
int indexOf(String str) // -1 if not found
boolean equals(Object other)
int compareTo(String other) // neg, 0, or pos
String[] split(String del) // NEW: splits around delimiter
Integer & Double Classes
Integer.MIN_VALUE // smallest int
Integer.MAX_VALUE // largest int
static int parseInt(String s) // String to int
static double parseDouble(String s) // String to double
Math Class
static int abs(int x)
static double abs(double x)
static double pow(double base, double exp)
static double sqrt(double x)
static double random() // [0.0, 1.0)
ArrayList Class
int size()
boolean add(E obj) // appends to end
void add(int index, E obj) // inserts, shifts right
E get(int index)
E set(int index, E obj) // returns OLD element
E remove(int index) // returns removed, shifts left
Scanner & File Classes (NEW)
File(String pathname) // File constructor
Scanner(File f) // Scanner constructor
int nextInt()
double nextDouble()
boolean nextBoolean()
String nextLine() // rest of line (watch buffer!)
String next() // next token/word
boolean hasNext() // true if more data
void close() // always close when done
Object Class
boolean equals(Object other)
String toString()
Top 10 Exam Traps
== vs .equals() — == checks if two references point to the same object. .equals() checks values. Always use .equals() for Strings and objects.5 / 2 gives 2, not 2.5. Cast to get decimal: (double) 5 / 2 gives 2.5.substring end is exclusive — "hello".substring(1, 3) returns "el" (indices 1 and 2 only, NOT 3)..length vs .length() vs .size() — Arrays: arr.length (no parens). Strings: str.length(). ArrayLists: list.size().0 to length - 1. Using <= instead of < throws ArrayIndexOutOfBoundsException.ConcurrentModificationException. Use a backward index-based loop.str.substring() does NOT change str. You must assign the result: str = str.substring(1);
Math.random() range — Returns [0.0, 1.0) meaning it CAN return exactly 0.0 but NEVER returns 1.0.nextLine() after nextInt() — nextInt() leaves a newline in the buffer. The next nextLine() returns an empty string. Call nextLine() once to clear it first.val = 0) does NOT change the original array element. Use an indexed loop to modify.Now You Know WHAT’s on the Exam. Need a Plan to Master It?
This cram sheet is your quick reference. The cram kits give you a day-by-day study plan with targeted practice, progress checkpoints, and exam-day strategy.
4-Week Cram Kit
28-day study plan. One unit per week with daily practice problems, self-assessments, and FRQ drills. The complete path from review to exam-ready.
Get the 4-Week Kit2-Week Cram Kit
14-day accelerated plan. High-yield topics only. Focused on the 80/20 — the concepts that appear most often on the exam.
Get the 2-Week Kit📄 Download the Printable PDF
Get the cram sheet as a clean, printable PDF. Perfect for last-minute review.
Get in Touch
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
Prefer email? Reach me directly at [email protected]