From the free course AP Computer Science A on Lykke
AP Practice 1
Key concepts: AP Computer Science A course and exam framework (effective Fall 2025) · Computational thinking practices and learning objectives · Program design and implementing a design or specification · Debugging programs · Data abstractions and data types · Determining initial conditions for code · Libraries in programming · Program documentation · Variables and primitive values · Assessing evidence and sources in AP courses
A correct Java program is not merely one that compiles: it must begin with appropriate conditions, use data abstractions correctly, and implement a clearly described design.
AP Practice 1
A correct Java program is not merely one that compiles: it must begin with appropriate conditions, use data abstractions correctly, and implement a clearly described design. The AP Computer Science A Course and Exam Description is effective Fall 2025, and its exam questions connect required content to named computational thinking skills.
For this practice set, the task type is multiple choice. The AP Exam includes 42 multiple-choice questions in 90 minutes, worth 55% of the exam score, followed by 4 free-response questions in 90 minutes, worth 45%. Multiple-choice questions may ask you to trace code, identify a design or precondition, recognize a data abstraction, or diagnose why code fails.
The reasoning pipeline
A reliable way to approach these questions is to move through the program like an engineer inspecting a machine:
- Specification: What is the code supposed to accomplish?
- Initial conditions: What must already be true before execution begins?
- Data model: What variables, objects, or collections represent the information?
- Execution: What does each statement do, in order?
- Debugging: If the result is wrong, does the problem involve syntax, state, logic, or an incorrect assumption?
These steps activate Practice 1: Design Code, Practice 2: Develop Code, Practice 3: Analyze Code, and Practice 4: Document Code and Computing Systems. In particular, the relevant skills are 2.B: Write program code involving data abstractions, 3.B: Determine the result or output based on code that contains data abstractions, 3.D: Explain why a code segment will not compile or work as intended and modify the code to correct the error, 4.A: Describe the behavior of a code segment or program, and 4.B: Describe the initial conditions that must be met for a code segment to work as intended or described.
Worked multiple-choice set: a library inventory
A community library stores the titles of books currently available for checkout. The program uses ArrayList, a class supplied by the Java Collections Library. A library class is prewritten code that programmers can use through its documented application programming interface (API)—the set of available constructors and methods. The programmer does not implement size() or get(); the library provides them.
import java.util.ArrayList;
ArrayList<String> titles = new ArrayList<String>();
titles.add("Orbit");
titles.add("Lantern");
titles.add("River");
int lastIndex = titles.size() - 1;
System.out.println(titles.get(lastIndex));
Question 1. What is printed?
- A.
Orbit - B.
Lantern - C.
River - D. Nothing, because
lastIndexis invalid
Answer: C. size() returns $3$, so lastIndex becomes $3 - 1 = 2$. ArrayList positions begin at index $0$, making index $2$ the third element, "River".
Examiner-rewarded reasoning: identify the collection’s size, convert the last position to size() - 1, and apply zero-based indexing. This tests 3.B: Determine the result or output based on code that contains data abstractions.
Data abstractions and library use
A data abstraction represents information while hiding unnecessary implementation details. Here, ArrayList<String> represents an ordered, resizable sequence of strings. The program calls add, size, and get without knowing how the collection stores its elements internally.
Question 2. Which change correctly prints every title in titles?
- A.
for (int i = 0; i < titles.size(); i++) System.out.println(titles.get(i)); - B.
for (int i = 0; i <= titles.size(); i++) System.out.println(titles.get(i)); - C.
for (int i = 1; i < titles.size(); i++) System.out.println(titles.get(i)); - D.
for (int i = 0; i < titles.size() - 1; i++) System.out.println(titles.get(i));
Answer: A. Valid indexes run from $0$ through size() - 1, so the loop condition must be i < titles.size(). Option B eventually requests index $3$, which is outside the valid range.
Misconception check — “The collection’s size is its final index.” size() counts elements; it does not identify the final index. For $n$ elements, the final valid index is $n - 1$.
Specifications and initial conditions
Suppose a method is intended to return the first title alphabetically:
public static String firstTitle(ArrayList<String> titles)
A useful specification states what the method does, what it returns, and what must be true before it runs. One necessary precondition is that titles is not null and contains at least one element; otherwise titles.get(0) cannot safely produce a first title.
Question 3. Which initial condition is sufficient for firstTitle(titles) to work as intended?
- A.
titleshas exactly one element - B.
titlesis not empty and contains nonullreference - C.
titlesis sorted in reverse alphabetical order - D.
titles.size()is equal to the first valid index
Answer: B. The method needs a usable first element and must be able to call collection methods on a valid reference. The condition does not require exactly one element or a particular ordering unless the specification says so.
This tests 4.B: Describe the initial conditions that must be met for a code segment to work as intended or described. A precondition is not the result of the method; it is a condition established before execution.
Debugging and documentation
Question 4. A programmer writes:
for (int i = 0; i <= titles.size(); i++) {
System.out.println(titles.get(i));
}
What is the best correction?
- A. Replace
<=with< - B. Replace
iwithi - 1 - C. Start
iat1 - D. Replace
size()withget()
Answer: A. The loop must stop before i reaches titles.size(). This is a boundary error: the final iteration attempts an invalid index. Explaining the cause and correcting the code demonstrates 3.D: Explain why a code segment will not compile or work as intended and modify the code to correct the error.
Documentation makes the design visible to other programmers. A concise comment could state: // Requires titles to contain at least one non-null title. Documentation should explain purpose, assumptions, and library behavior—not repeat obvious syntax.
Timing and error review
For a short multiple-choice set, spend about 2 minutes per question: read the specification, trace only the relevant state, and eliminate answers that violate indexing or type rules. After checking your answers, label each error as a trace error, data-abstraction error, precondition error, or debugging error; then rewrite the rule that would have prevented it.







Source Materials
- AP Computer Science A Course and Exam Description
- AP Computer Science A Course and Exam Description Clarifications and Corrections
- AP Computer Science A Course Overview
- AP Computer Science A Course at a Glance
- AP Computer Science A Course at a Glance Poster
- Adopt AP Computer Science A
- AP Computer Science A
- AP Computer Science A
- Figure — Sample Responses Q1 (p. 3)
- , .:
- ,'\.-,' " ..
- "t , .- A \: