Overview
AP Computer Science A Practice 4: Document Code and Computing Systems is the skill of describing what a program does and the conditions that produce a specific result. You read a code segment, then explain its overall behavior in plain language or identify what inputs and starting values it needs to work correctly. This practice is about understanding and communicating the purpose of code, not just tracing a single output.
Practice 4 shows up only on the multiple-choice section. It carries roughly 10 to 15 percent of the multiple-choice weighting, so it is worth real points but smaller than Practice 2 (Develop Code) and Practice 3 (Analyze Code).

What Practice 4 - Document Code and Computing Systems Means
This practice has two subskills, both tested on the MCQ section and neither on the FRQ section.
- 4.A: Describe the behavior of a code segment or program. You summarize what the code accomplishes as a whole. Instead of "what prints on this exact input," you answer "what does this code do for any valid input."
- 4.B: Describe the initial conditions that must be met for a code segment to work as intended or described. You identify the starting values, inputs, or array contents that have to be true so the code produces the described result.
The connecting idea is documentation. A good description and a clear set of preconditions are how programmers communicate intent.
What This Practice Requires
You need to do two related things.
- Generalize behavior. Read past one specific run and state the rule the code follows. For example, recognizing that a loop multiplies together only the positive values in a 2D array.
- Work backward from a goal. Given a target result, find the inputs or initializations that make it happen. For example, choosing the array contents that make a column sum equal 3.
Both require careful reading of loops, conditionals, method calls, and array indexing without losing the big picture.
Skills You Need for This Practice
- Trace loops and conditionals well enough to see the pattern, then describe it in one sentence.
- Recognize what a condition filters or selects, like
if (value > 0)keeping only positive numbers. - Understand array and 2D array indexing, including which index is the row and which is the column.
- Connect a described outcome back to required inputs, such as nonempty arrays or specific ranges.
- Read method headers and preconditions, like
/** Precondition: ranges contains at least one element. */.
How It Shows Up on the AP Exam
- Only multiple-choice. Practice 4 is not assessed on the four free-response questions.
- Behavior questions (4.A) often ask "which of the following best describes the behavior of the code segment?" The answer choices are full-sentence descriptions, and one captures what the code does for all valid inputs.
- Condition questions (4.B) often ask which initialization or input "will cause the code segment to print" a specific value or "works as intended." You pick the starting data that produces the stated result.
- Distractors usually describe a closely related but wrong behavior, such as "product of all negative elements" instead of positive, or an initialization that produces a different sum.
Examples Across the Course
These pull from different units so you can see Practice 4 across content areas.
Unit 4, 2D arrays (4.A, behavior).
</>Javaint[][] arr = {{10, -7, 19, 14}, {-3, -2, -6, 11}, {-9, 12, 10, -1}}; int ans = 1; for (int[] row : arr) for (int value : row) if (value > 0) ans = ans * value; System.out.println(ans);
The best description: it prints the product of all the positive elements in arr. The if (value > 0) filter and the multiplicative start ans = 1 are the keys.
Unit 4, 2D arrays (4.B, conditions).
</>Javaint[][] arr2D = /* missing initialization */; int sum = 0; for (int j = 0; j < arr2D.length; j++) sum += arr2D[j][2]; System.out.println(sum);
To print 3, the initialization must put values in column index 2 (the third column) that add up to 3. A three-row array with a 1 in column 2 of each row works.
Unit 2, loops (4.A, behavior). A while loop containing a for loop that runs a fixed number of times each pass executes its inner statement (outer count) times (inner count). Describing this as "repeats the inner action a set number of times for each outer pass" is a behavior summary.
Unit 4, arrays with preconditions (4.B, conditions). A method labeled /** Precondition: ranges contains at least one element. */ only works as described when that precondition holds. Recognizing that an empty array would break a max-finding method is condition reasoning.
Unit 1 and Unit 3, objects (4.B, conditions). A constructor like Date(String m, int d) requires arguments matching those types in that order. Describing the conditions to create a valid object means knowing the constructor's parameter list must be satisfied.
How to Practice Practice 4 - Document Code and Computing Systems
Practical advice, not official rules:
- After tracing any code, force yourself to write one sentence: "This code does ___ for any valid input." That trains 4.A directly.
- For 4.B, start from the desired output and ask "what would have to be true at the start?" Test your answer by plugging it in.
- Pay attention to accumulator starting values.
sum = 0andproduct = 1change what counts as correct behavior. - Note index choices in 2D arrays.
arr2D[j][2]always touches column 2, so conditions live in that column. - Read preconditions in method comments and treat them as required initial conditions.
Common Mistakes
- Describing one run instead of the rule. A 4.A answer should hold for all valid inputs, not just the example values shown.
- Confusing related behaviors. Mixing up positive vs negative, sum vs product, or rows vs columns leads straight to a distractor.
- Ignoring the starting value. Forgetting that
ans = 1makes the loop a product, not a sum. - Mixing up row and column indexing in 2D array condition questions.
- Overlooking preconditions. Choosing an input that violates a stated precondition, like passing an empty array, breaks "works as intended."
Quick Review
- Practice 4 has two subskills: 4.A describe behavior, 4.B describe required initial conditions.
- Both are MCQ only, about 10 to 15 percent of the multiple-choice section.
- 4.A asks what the code does in general; pick the description true for all valid inputs.
- 4.B asks what inputs or initializations make a described result happen; work backward from the goal.
- Watch accumulator start values, condition filters, array indexing, and stated preconditions.