AP Computer Science A Unit 1 Cheat Sheet
A one-page visual summary of Using Objects and Methods — every type, operator, method call, and exam trap you need, on a single screen.
← Back to Unit 1 hub
The basics
What it covers: Java data types, expressions and output, casting, operators, the API, method signatures, objects, and the Math and String classes.
Exam weight: About 15–25% of the multiple-choice section.
The big question: How do you store data, build expressions, and use objects and methods in Java?
Computational thinking practices: Design Code, Develop Code, Analyze Code, Document Code, and Use Computers Responsibly.
Key topics at a glance
Primitive Types
int (integers), double (real numbers), boolean (true/false). Everything else is a reference type (objects like String).
Arithmetic & Precedence
Operators + − * / %. Precedence: * / % before + −; parentheses first; equal precedence goes left to right.
Integer vs. Double Division
int / int truncates (7 / 2 = 3). Use a (double) cast for real division: (double) 7 / 2 = 3.5. % gives the remainder.
Output
System.out.print(x) stays on the line; System.out.println(x) adds a new line.
Casting
(int) truncates a double toward zero; (double) makes an int a real number. Cast can lose information or overflow the int range.
Compound & Increment
+= -= *= /= %= combine an operation with assignment. ++ adds 1, −− subtracts 1.
Calling Methods
Class.method(args) for static (Math.sqrt); object.method(args) for instance (str.length()). Use the dot operator.
Strings
A String is immutable. Concatenate with +. Methods: length(), substring(from, to), indexOf(str), equals(other), compareTo(other). Indices start at 0.
The key terms and rules you must know
- Primitive types — int, double, boolean.
- Reference type — a variable that refers to an object (e.g., String).
- Arithmetic operators — + − * / %.
- Integer division — int / int truncates toward zero.
- Remainder — % gives the remainder after division.
- Operator precedence — * / % before + −; parentheses override.
- Casting — (int) truncates; (double) makes a real number.
- Compound assignment — += −= *= /= %=; ++ and −−.
- Method signature — name + parameter types.
- new + constructor — creates (instantiates) an object.
- Dot operator — calls a method on a class or object.
- String immutability — methods return new Strings; use equals() to compare.
Key themes to remember
- Types drive behavior. int, double, and boolean each have their own values and operations.
- int / int truncates. Cast to double when you need a real quotient.
- Precedence is fixed. Use parentheses to make intent clear.
- Objects come from classes. new + a constructor makes an instance you call methods on.
- Strings never change. Method calls return new Strings; compare with equals(), not ==.
Common exam traps
- 7 / 2 is 3, not 3.5 — integer division truncates.
- Cast before dividing: (double) 7 / 2 = 3.5, but (double)(7 / 2) = 3.0.
- Use equals() for Strings, not == (which compares references).
- String indices start at 0; substring(from, to) excludes index to.
- Math.random() is in [0, 1) — never returns exactly 1.0.
- ++ changes the variable. x++ is x = x + 1, not just reading x.
- Watch precedence: 2 + 3 * 4 is 14, not 20.