DAY 4 | Objects + Methods
Unit 1 | 15–25% of exam | Foundation for everything
Your Plan for Today
apcsexamprep.com/pages/ap-csa-unit-1-complete-study-guide
Focus: primitive types, String methods, casting, Math class, passing arguments.
apcsexamprep.com/pages/ap-csa-unit-1-practice-exam
Do 10 questions.
-> Score 8-10: move to Step 3.
-> Score 5-7: reread String methods and integer division sections.
-> Score 0-4: reread the entire Unit 1 study guide. Unit 1 is the foundation.
Use: 2023 AP CSA Free Response Question 1 (AppointmentBook)
apcsexamprep.com/pages/ap-csa-2023-frq-1-appointmentbook
Write Parts A and B on paper. Check solution after both parts are done.
| Your Score |
What to Do |
| 0–3 pts |
Reread the methods section of Unit 1 study guide. Then try 2022 FRQ 1. |
| 4–6 pts |
Review the rubric, then move to Day 5. |
| 7–9 pts |
Great. Move to Day 5. |
Concept Review
Primitive Types and Expressions
- Primitives:
int, double, boolean, char — stored by value
- Integer division:
7 / 2 = 3 (truncates, does NOT round)
- To get a decimal: use
7.0 / 2 or (double) 7 / 2
- Casting:
(int) 3.9 truncates to 3 — it does not round
-
Math.random() returns a double in [0.0, 1.0) — never returns exactly 1.0
String Methods — 2026 Quick Reference
-
s.length() — number of characters
-
s.substring(a, b) — chars from index a up to (NOT including) b
-
s.substring(i, i + 1) — single char at index i — use this, NOT charAt
-
charAt is NOT on the 2026 AP Quick Reference — do not use it
-
s.indexOf(str) — first index where str appears, or -1 if not found
-
s.equals(t) — true if same content | == compares references, not content
Practice Questions
Q16. [TRACE]
What does this print?
double d = 7 / 2;
System.out.println(d);
- (A) 3
- (B) 3.5
- (C) 3.0
- (D) Compile error
▶ REVEAL ANSWER
Answer: C
7 / 2 evaluates to 3 (integer division). Stored in double d, becomes 3.0. Prints 3.0.
Q17. [SPOT THE ERROR]
This code is supposed to print 'same' when two Strings contain the same text. What is wrong?
String s1 = "hello";
String s2 = new String("hello");
if (s1 == s2)
{
System.out.println("same");
}
else
{
System.out.println("different");
}
- (A) s1 == s2 correctly compares string content
- (B) s1 == s2 compares references, not content -- may print 'different' even when text matches
- (C) new String("hello") is not valid Java syntax
- (D) The if and else blocks should be swapped
▶ REVEAL ANSWER
Answer: B
== compares memory addresses, not text. new String() creates a new object at a different address. Always use .equals() to compare String content.
Q18. [ALWAYS/NEVER]
According to the 2026 AP CSA Quick Reference, which correctly retrieves the character at index i from String s?
- (A) s.charAt(i)
- (B) s[i]
- (C) s.substring(i, i + 1)
- (D) s.get(i)
▶ REVEAL ANSWER
Answer: C
charAt is NOT on the 2026 Quick Reference. s[i] is array syntax -- invalid for Strings. s.get(i) is an ArrayList method. s.substring(i, i + 1) is correct.
Q19. [I/II/III]
Which are TRUE about passing arguments to methods?
I. Passing a primitive int and changing the parameter does NOT affect the caller.
II. Passing an ArrayList and calling list.add() DOES modify the original.
III. Passing a String and reassigning the parameter changes the caller's String.
- (A) I only
- (B) I and II only
- (C) II and III only
- (D) I, II, and III
▶ REVEAL ANSWER
Answer: B
I TRUE -- primitives are copied. II TRUE -- ArrayList is an object; method and caller share it. III FALSE -- reassigning the parameter only changes the local reference.
Q20. [TRACE]
What is the output?
String s = "hello";
System.out.println(s.substring(1, s.length()));
- (A) hello
- (B) ello
- (C) hell
- (D) hel
▶ REVEAL ANSWER
Answer: B
substring(1, s.length()) returns characters at indices 1 through 4: 'ello'.
Answer Key (for printing)
Q16: C Q17: B Q18: C Q19: B Q20: B