Overview
AP Computer Science A Practice 2 - Develop Code is the skill of writing and implementing working Java program code. Instead of just reading or analyzing code, you produce it: you translate an algorithm into syntax, build classes and objects, and call methods to get the result a problem asks for.
This practice shows up everywhere on the exam. It carries an approximate weighting of 22 to 38 percent of the multiple-choice section, and all four free-response questions ask you to write code. If you can develop correct code, you are set up to earn points across the whole test.

What Practice 2 - Develop Code Means
Develop Code covers three related subskills:
- 2.A Write program code to implement an algorithm.
- 2.B Write program code involving data abstractions.
- 2.C Write program code involving procedural abstractions.
The common thread is production. You are not predicting output (that is Practice 3) or describing behavior (that is Practice 4). You are writing the statements that make a program do what is described.
What This Practice Requires
Here is what each subskill asks you to do.
2.A Implement an algorithm Turn a described process into code using sequencing, selection, and iteration.
- Choose the right control structure:
if,if-else,while,for, or nested loops. - Get loop bounds and conditions exact so you cover the intended range with no off-by-one errors.
- Combine Boolean expressions correctly with
&&,||, and!.
2.B Use data abstractions Write code that creates and works with data structures and objects.
- Instantiate objects with the correct constructor and argument types.
- Create and traverse arrays,
ArrayListobjects, and 2D arrays. - Use wrapper classes and
Stringmethods to store and transform data.
2.C Use procedural abstractions Write code that calls and builds methods.
- Call instance methods on the correct object, and call static methods on the class.
- Respect access rules: you can call public methods from another class, but not private ones.
- Pass the right number and type of arguments, and use return values correctly.
Skills You Need for This Practice
You pull from across all four units when you develop code:
- Unit 1: declaring variables, casting, calling
MathandStringmethods, creating objects. - Unit 2: Boolean logic,
if-elsechains,whileandforloops, nested iteration. - Unit 3: writing constructors, accessor methods, and instance methods inside a class you design.
- Unit 4: building and traversing arrays,
ArrayListobjects, 2D arrays, and reading from text files.
Syntax accuracy matters here in a way it does not for analysis questions. A misplaced semicolon or wrong method name means the code will not compile.
How It Shows Up on the AP Exam
Multiple choice
You choose the code segment that correctly fills a /* missing code */ blank or correctly creates an object.
- 2.A questions ask you to pick the loop header or
if-elsestructure that produces a stated result. - 2.B questions test correct object creation and data structure use.
- 2.C questions test which method call compiles given access modifiers.
Free response All four FRQs assess developing code:
- Question 1: Methods and Control Structures (7 points)
- Question 2: Class Design (7 points)
- Question 3: Data Analysis with
ArrayList(5 points) - Question 4: 2D Array (6 points)
You are given the Java Quick Reference, so you do not need to memorize every library method signature.
Examples Across the Course
Example 1 (2.A, Unit 2): an if-else chain for year categories
A method returns "Renaissance" for years 1400 to 1600, "Medieval" for 400 to 1399, and "Other" otherwise. Order and else if matter.
</>Javaif (year > 1600 || year < 400) { category = "Other"; } else if (year >= 1400) { category = "Renaissance"; } else if (year >= 400) { category = "Medieval"; }
Separate if statements without else would overwrite earlier correct values, so chaining is the fix.
Example 2 (2.A, Unit 2): a nested loop that shrinks each row
To print 0 1 2 3, then 0 1 2, then 0 1, then 0, the inner loop bound depends on the outer counter.
</>Javafor (int j = 4; j > 0; j--) { for (int k = 0; k < j; k++) { System.out.print(k + " "); } System.out.println(); }
Example 3 (2.B, Unit 1 and 3): creating an object with the right constructor
Given public Date(String m, int d), only a call with a String then an int works.
</>JavaDate birthday = new Date("September", 5);
A call like new Date("September", "5th") fails because the second argument type is wrong, and you cannot assign to month or day directly since they are private.
Example 4 (2.B, Unit 4): building usernames from a text file
Reading lines like Cohen-Isabel and producing "ICohen" requires splitting on the dash.
</>Javawhile (scan.hasNext()) { String[] temp = scan.next().split("-"); usernames.add(temp[1].substring(0, 1) + temp[0]); }
Here temp[0] is the last name and temp[1] is the first name, so you take the first letter of temp[1] and join it to temp[0].
Example 5 (2.C, Unit 3): calling methods with correct access and target
In a Duplex class with two private Apartment fields, you call a public method on an object, not on the class, and you cannot reach a private method from outside.
</>JavaunitOne.calculateRent() // public, called on an object: works
Apartment.calculateRent() fails because the method is not static, and getTenant() fails because it is private.
How to Practice Practice 2 - Develop Code
These are practical study suggestions, not official rules.
- Write code by hand or in a plain editor without autocomplete so you catch your own syntax slips.
- For every algorithm, trace your loop bounds with a small input before trusting it.
- Practice object creation by matching constructor parameter types exactly.
- Drill method calls: ask yourself whether the target is an object or a class, and whether the method is public.
- Use full FRQ prompts since all four require you to develop code. Compare your answer to a scoring guide line by line.
- Keep the Java Quick Reference handy while practicing so you learn what is available to you.
Common Mistakes
- Using separate
ifstatements where anif-elsechain is needed, which lets later conditions overwrite correct answers. - Off-by-one loop bounds, such as
<=instead of<, that add or drop one iteration. - Calling a private method from outside its class, or calling an instance method on the class name.
- Passing arguments in the wrong type or order to a constructor.
- Forgetting that
Stringmethods likesubstringreturn a new value rather than changing the original. - Splitting fields incorrectly, for example mixing up
temp[0]andtemp[1]after asplit.
Quick Review
- Practice 2 means you write and implement code, not just read it.
- 2.A implements algorithms with selection and iteration.
- 2.B creates and uses data abstractions like objects, arrays, and
ArrayListobjects. - 2.C calls and writes methods while respecting access and static rules.
- This practice covers 22 to 38 percent of multiple choice and appears in all four FRQs.
- Syntax precision, correct loop bounds, correct constructor arguments, and correct method targets are where points are won or lost.