Course guides
How to Study for a Programming Exam: Trace, Write and Debug Code on Paper
Intro programming finals test four skills: tracing code, writing it by hand, finding bugs and sizing up running time. Here's how to drill each one, the loop patterns to know cold, free graded practice and a countdown.
By the Lykke team19 min read
Key takeaways
- Intro programming finals usually mix four question types: trace the output, write a method, find the bug, and say how a loop's work grows. Practice each one in your exam's format.
- Learn the standard loop patterns (sum, count, minimum or maximum, any, all, consecutive pairs, reverse) until you can write each from a blank page in your course's language.
- Write code by hand with no autocomplete, trace it on a tiny input, then type it in and run it. Every mismatch shows a gap in how you check code.
- AP Computer Science A free-response questions and their scoring guidelines are free on College Board's site, and the rubrics show exactly how partial credit works.
- On exam day, read the whole question, write the header first, test your answer on a small example, and never leave a question blank.
In this guide
- What a programming final asks: four question types
- How to trace code by hand without slipping
- How to write code on paper
- Learn patterns, not pages of syntax
- Find-the-bug questions: the slips that keep coming back
- How to answer Big-O questions in an intro course
- Recursion and object-oriented questions
- Where to find practice questions: old exams and AP free-response questions
- A 14-day countdown to your programming final
- On exam day: read, plan, test and take the partial credit
- FAQ
- Sources
Here's how to study for a programming exam: find out exactly what the final looks like, then practice the questions it asks under the same conditions. In an intro course, in Java or Python, that usually means four question types: tracing code to predict what it prints, writing a method or function from a description, finding the bug in code that almost works, and saying how a loop's work grows with its input. Recursion and classes can turn up in any of them.
Rereading slides won't build those skills. Below: how to drill each question type, with worked examples in Java and Python, the loop patterns to know cold, what graders forgive (College Board publishes its rules), free practice questions with real rubrics, a 14-day countdown and the exam-day habits that protect partial credit.
What a programming final asks: four question types
Start with the format, because programming exams vary more than most. Check the syllabus or course site for four things: paper or computer, what you may bring, how long it runs, and whether old exams are posted. Three current examples:
- UW's CSE 121 (Java), autumn 2026: the final is on paper, 60 minutes, with six questions. The course provides a reference sheet, and students may bring one sheet of their own notes, front and back (CSE 121 exam rules).
- Stanford's CS106A (Python), summer 2026: a closed-book paper exam with a reference sheet plus two sheets of your own notes. Most questions would ask for a function or short passage of code, others for reading code and reasoning about it (CS106A final exam).
- AP Computer Science A (Java): 42 multiple-choice questions worth 55% and four free-response questions worth 45%, 90 minutes per section. Between 37% and 53% of the multiple-choice weight goes to analyzing code: working out what it outputs, or why it doesn't work as intended (AP CSA Course and Exam Description). Since 2025 the exam has been given in College Board's Bluebook app, where free-response code is typed but never compiled (2025 Chief Reader Report).
Whatever the format, the questions sort into four types:
| Question type | What it asks | The skill underneath | Practice it free |
|---|---|---|---|
| Trace the output | What does this print? What does x hold after the loop? | Running code in your head, one line at a time | Array Memory Visualizer (Java), The Stack & State Visualizer (Python) |
| Write a method | Write a function that meets a description and its examples | Matching a spec to a pattern, then to code | AP CSA 4.5 Implementing Array Algorithms |
| Find the bug | Why does this fail, and what one change fixes it? | Comparing what code does with what it should do | AP Practice 2 (Java), The Debugging Sandbox (Python) |
| Efficiency (Big-O) | How does the work grow when the input doubles? | Counting how often a statement runs | AP CSA 2.12 Informal Run-Time Analysis |
Recursion, classes and efficiency often come last in the term, and finals can lean on recent material: Stanford's summer final was weighted toward the second half of the course. Cornell's CS 1110 (Python) says recursion and classes feature heavily on its second prelim, ahead of a comprehensive final (CS 1110 exams), and MIT's 6.100L taught recursion, classes, inheritance and Big-O in weeks 9 to 13 of 15 (6.100L calendar).
How to trace code by hand without slipping
Every other question type rests on tracing: you can't check code you wrote on paper, or find a bug, without running it in your head. If the basic method (a table with one column per variable) is new to you, start with our guide to whether intro CS is hard. Exam tracing questions are built around a handful of traps:
- A value changed earlier in the same loop. If a loop reads a[i - 1] after updating it, it gets the new value, not the original.
- End points. Java's substring(from, to) stops at index to - 1 (AP CSA Course and Exam Description), and Python's range never includes its end point (Python tutorial). Off-by-one answers come from here.
- Integer division. In Java, dividing one int by another keeps only the integer part of the quotient. In Python, / gives a float even when both numbers are integers, and // rounds down (Python language reference).
- Short-circuit logic. Java stops evaluating && or || as soon as the first operand decides the answer, so the second condition may never run. Try it in the free Short-Circuit Logic Lab demo.
- Two names, one object. Assigning an array, list or object to a second variable doesn't copy it, so a change through one name shows up through the other. The Array Memory Visualizer in the table above draws both cases.
Worked example: a running total that sneaks up on you
What does this Java code print?
int[] a = {2, 4, 6, 8};
for (int i = 1; i < a.length; i++) {
a[i] = a[i] + a[i - 1];
}
System.out.println(Arrays.toString(a));
Write one row per pass and update the array as you go:
| i | a[i - 1], already updated | a[i] before | a[i] after | The array after this pass |
|---|---|---|---|---|
| 1 | 2 | 4 | 6 | [2, 6, 6, 8] |
| 2 | 6 | 6 | 12 | [2, 6, 12, 8] |
| 3 | 12 | 8 | 20 | [2, 6, 12, 20] |
It prints [2, 6, 12, 20]. The tempting wrong answer, [2, 6, 10, 14], adds each element's original left neighbor. Misses on questions like this come from skipped rows, so write every row even when you think you see the pattern.
How to write code on paper
Handwritten code feels slow because nothing finishes your lines, flags a typo or runs your program. On a paper exam, you are the compiler and the test suite, which is why UW's CSE 121 staff tell students to practice writing code by hand. A routine for any write-a-method question:
- Copy the header exactly as given. AP graders withhold the algorithm points when a provided method header is rewritten with a different number or type of parameters (2026 AP CSA scoring guidelines), and the 2025 chief reader urged practice writing class and method headers without help from tools.
- Turn the examples into test cases first. Note each input and expected result from the question, then add one tiny case of your own: an empty list, a single item or a value right at a boundary.
- Name the pattern. A sum, a count, a maximum, an any-or-all check? Write that skeleton before the details.
- Leave a blank line between statements, as UW's TAs suggest, so you can add code later. An arrow showing where an insertion goes is fine.
- Trace your answer on the smallest example. The 2025 chief reader recommends tracing drafts on small, concrete lists of four or five elements.
- Then type it in and run it. Every difference between your trace and the real output marks a gap in how you check code. Look at the official solution last; as UW's staff put it, you can't unsee it.
When the typed version disagrees with your trace, step through it in a debugger to find the line where they split. The Missing Semester's Debugging and Profiling section covers the tools.
Learn patterns, not pages of syntax
Most exam methods are a familiar pattern with one twist. A University of Washington team describes programming as four skills that build on each other: tracing, writing correct syntax, recognizing templates (reusable chunks of code, such as swapping two variables) and writing new code with them. In their small exploratory study of nine beginners, those taught the skills one at a time completed more practice exercises and made fewer errors (Xie et al., 2019).
College Board's course framework spells out the standard array patterns AP students should be able to write (CED, topic 4.5), and they turn up in intro finals in either language:
| Pattern | The move | Common slip |
|---|---|---|
| Sum or average | Set the total to 0 before the loop, add inside it | Resetting the total inside the loop; integer division in Java |
| Count matches | Add 1 only when the condition holds | Adding 1 for every element |
| Minimum or maximum | Start from the first element | Starting from 0, so the maximum of all-negative values comes out as 0 |
| At least one matches | Return true inside the loop, false after it | Returning false at the first non-match |
| All match | Return false inside the loop, true after it | Returning true at the first match |
| Consecutive pairs | Compare item i with item i + 1 | Letting i reach the last index, one step out of bounds |
| Duplicates | Compare each item with every later item | Comparing an item with itself |
| Shift or rotate | Save the item that falls off the end first | Overwriting it before it's saved |
| Reverse in place | Swap item i with item n - 1 - i, for the first half only | Looping the full length, which swaps everything back |
Write each one from a blank page in your course's language until you don't need notes: Java students with AP CSA 2.9 Implementing Selection and Iteration Algorithms, Python students with the lists and sequences unit of Intro to Python Fundamentals. UW's TAs suggest a habit for spotting patterns: after each practice problem, compare it with ones you've solved, since many share themes such as traversals, finding a minimum or maximum, and indexOf.
What graders forgive, and what they don't
On AP's rubric, at least, punctuation slips cost less than logic errors. College Board's 2026 scoring guidelines list errors that don't cost points, including a missing semicolon or brace where the structure is clear, mixing up length and size, and spelling slips with no ambiguity. The algorithm points go, though, when steps are missing or out of order, when square brackets replace .get on an ArrayList, when a void method returns a value, or when a provided header gets a different number or type of parameters. The 2025 chief reader also warned that these rules get revisited, so students shouldn't assume any missing or extra element will be ignored. Stanford's CS106A staff took a similar line in a 2018 handout: lenient with syntactic errors, not conceptual ones, when the intent is clear (CS106A exam strategies).
So learn the core syntax of your language, then put most of your hours into logic. Your own course's rules decide; ask if the syllabus doesn't say.
Find-the-bug questions: the slips that keep coming back
A bug question usually hides one wrong line in code that looks reasonable. This Python function should report whether every score passes:
def all_passing(scores):
for s in scores:
if s >= 60:
return True
else:
return False
Trace it on [70, 40]: the first score is 70, so it returns True without ever looking at 40. The fix is the all-match pattern from the table:
def all_passing(scores):
for s in scores:
if s < 60:
return False
return True
Then check the edge cases. The fixed version returns True for an empty list, since no score fails, so see whether the question says what an empty list should give. The buggy one returns None there, because a Python function that ends without reaching a return statement returns None.
Other slips that turn up often:
- Integer division in Java. If the sum and the count are both ints, sum / count drops the fraction, so the average of 1 and 2 comes out as 1.0. Cast first: (double) sum / count.
- == on Java strings. == asks whether two references point to the same object, while equals compares the characters. Write answer.equals("yes"), not answer == "yes".
- A range written like algebra. College Board's 2025 report says a significant number of responses wrote 9 <= i <= 17, which doesn't compile in Java; you need 9 <= i && i <= 17. Python allows that chained form, so this one bites Java students.
- An accumulator that never accumulates. The same report saw totals that were never initialized, or that were assigned with = instead of added to.
- Printing instead of returning. On the 2026 AP class-design question, printing the value instead of returning it, or as well as returning it, cost the return point.
- A method called without its object. On 2025's first question, the overwhelming majority of responses called another class's methods without naming the object to call them on.
For Java practice, Lykke's free AP CSA course page has AP Practice 2 on debugging; for Python, try the Debugging and Error Types unit.
How to answer Big-O questions in an intro course
Intro courses ask about efficiency in two ways: count how many times a statement runs (AP CSA's statement execution count), or name how the work grows, as in the lecture MIT's 6.100L gives to Big-Oh and Big-Theta notation. Either way, find the statement in the innermost loop, count its runs for a small n, then double n and count again.
| Loop shape | Runs when n = 8 | Runs when n = 16 | Growth |
|---|---|---|---|
| One loop from 0 to n | 8 | 16 | O(n) |
| Two loops from 0 to n, one after the other | 16 | 32 | O(n) |
| A loop from 0 to n inside another | 64 | 256 | O(n²) |
| An inner loop that starts at i + 1, so each pair runs once | 28 | 120 | O(n²) |
| i starts at n and halves each pass while i > 1 | 3 | 4 | O(log n) |
Three rules handle the common cases: loops one after another add, nested loops multiply, and a variable that halves each pass gives about log₂ n passes. So doubling n doubles linear work, roughly quadruples quadratic work and adds one pass to logarithmic work. Practice on AP CSA 2.12 and the free Search Algorithm Efficiency Duel demo, which races linear search against binary search and counts each one's operations.
If your course goes further (Big-Omega, amortized cost, recurrences), you're into data structures territory: see how to study for data structures and the free Union-Find and Big O Analysis section.
Recursion and object-oriented questions
Tracing recursion
What does mystery(5) print?
public static void mystery(int n) {
if (n <= 0) {
return;
}
System.out.print(n + " ");
mystery(n - 2);
System.out.print(n + " ");
}
Each call prints its n, waits for the smaller call to finish, then prints n again. The calls go 5, 3, 1, then -1 hits the base case, so the output is 5 3 1 1 3 5: work before the recursive call happens on the way down, and work after it on the way back up. On paper, draw one box per call, stacked, and cross each out as it returns. The free Recursion: The Call Stack Visualizer demo steps through the call stack of a recursive factorial in Java.
AP Computer Science A only asks students to trace recursion: writing recursive code is outside the course and exam (CED, topic 4.16). College courses can ask you to write one, so check your old exams. Lykke's free AP CSA 4.16 Recursion section covers recursion the way AP tests it.
Writing a recursive function
Use the same three parts every time: a base case that needs no recursion, a call on a smaller input, and a step that combines the result. Here's one that counts how many times a value appears in a Python list:
def count(items, target):
if not items: # base case: an empty list
return 0
rest = count(items[1:], target) # trust the smaller call
return rest + (1 if items[0] == target else 0)
count([3, 1, 3], 3) returns 2. Before you move on, check that every call gets closer to the base case; a call that doesn't shrink its input never stops. The Recursion, Efficiency, and OOP section of the free intro CS course covers recursive functions in Python.
Writing a class
Class-writing questions reward structure. On the 2026 AP class-design question, five of the seven points went to the skeleton: the class header, private instance variables, the constructor header, a constructor that assigns the correct starting value, and the method header. One point went to the algorithm and one to returning the result rather than printing it. So write the skeleton first:
- The instance variables: private in Java, set on
selfin__init__in Python. - A constructor that initializes every one of them, which the 2025 chief reader also stressed.
- Methods that use the instance variables, not new local variables with the same names.
- A return statement on every path of a method that promises a value.
To see objects and fields in memory, try the OOP Memory Visualizer (Java) or the OOP: Class vs Instance Visualizer (Python). AP Practice 3 works through class-design responses in Java.
Inheritance: which method runs?
If your course teaches inheritance, expect a question like this:
class Pet {
String sound() { return "..."; }
String greet() { return "The pet says " + sound(); }
}
class Dog extends Pet {
String sound() { return "woof"; }
}
Pet p = new Dog();
System.out.println(p.greet());
It prints "The pet says woof". greet() is inherited from Pet, but the sound() call inside it runs Dog's version, because Java calls the method of the object a variable refers to, not the one defined by the variable's type (Oracle's Java Tutorials). AP CSA leaves designing inheritance out of its exam, but college courses can include it: MIT's 6.100L, for one, gave it two lectures, in Python.
Where to find practice questions: old exams and AP free-response questions
Your own course's old exams come first
They match your professor's style and difficulty better than anything else. Cornell's CS 1110 posts its prelims and finals from fall 2021 on, with solutions, and warns that topics shift between semesters, so check each question against your syllabus. Stanford's CS106A says its section exercises are similar in size and scope to exam questions, and many first appeared on exams. Take at least one old exam under the real rules: same medium, same notes, same time limit.
AP Computer Science A free-response questions
When you run out, College Board's free-response questions are free Java practice with official rubrics. AP CSA is a high school course, but College Board describes it as equivalent to an introductory college course in computer science. Its past exam questions page has the 2023 to 2026 questions with scoring guidelines, plus sample responses and chief reader reports for 2023 to 2025 (AP CSA past exam questions). The May 2026 set, the first under the revised course, has one question each on methods and control structures, class design, ArrayList data analysis and 2D arrays, worth 7, 7, 5 and 6 points (2026 free-response questions).
How to use them:
- Give each question about 22 minutes, the real section's pace.
- Answer on paper or in a plain text editor, with no autocomplete and no running, as on the real exam.
- Score yourself with the scoring guidelines, point by point, and note every point you lost.
- Read that year's chief reader report, which lists the misconceptions graders saw next to corrected code.
- Then type your answer into an editor and test it on the question's examples.
Two limits: College Board says the older questions don't fully match the current exam, and AP never asks you to write recursive code or design inheritance. Python students can still use them, with a list for each ArrayList and a list of lists for each 2D array. For more in the same style, Lykke's free AP Computer Science A course page has practice sections such as AP Practice 4 on 2D arrays. AP courses cover intro college-level material, so treat them as extra practice, not a map of your final.
Thinking of asking an AI chatbot for more practice problems? Check your syllabus first, because some courses limit what you may paste into one (how to read your course's AI policy).
A 14-day countdown to your programming final
Count back from your exam date. With several finals, our finals guide shows how to split hours across them; this is the programming part of that plan.
| Days before the exam | Focus | What you do |
|---|---|---|
| 14–13 | Map the exam | Confirm the format, what you can bring and what it covers. Gather old exams and sort every question by type: trace, write, bug, Big-O, recursion, classes. |
| 12–9 | Mixed daily drills | Each day: two traces, one method on paper and one bug hunt, from different weeks of the course. Type each answer in, run it and log every miss. |
| 8–6 | Late topics | Recursion and classes every day, plus one timed AP free-response or old exam question scored with its rubric. Start your cheat sheet if one is allowed. |
| 5 | Full practice exam | One old final, timed, under the real rules. |
| 4–2 | Fix the misses | Rework every miss from a blank page. Write each loop pattern from memory once a day. Finish the cheat sheet. |
| 1 | Light review | Two easy traces and a pass through your miss log, then stop at a normal hour. |
Mixing question types is deliberate: it makes you decide which pattern a question needs, the way the exam will. For quizzing yourself between drills, see our guide to active recall. If Thanksgiving break falls inside your countdown, the Thanksgiving break study plan shows how to fit review around travel; down to one day, use the one-day exam plan.
On exam day: read, plan, test and take the partial credit
- Scan the whole exam, then budget minutes by points. Stanford's handout suggests dividing the total minutes by the total points; UW's CSE 121 final this autumn gives 60 minutes for six questions, about 10 minutes each.
- Read every word of the question, preconditions included. The 2026 AP directions say to assume parameters aren't null and preconditions are met, so checking them wastes time, and a wrong check can cost the algorithm point. Long stretches of code that a provided method could replace won't get full credit either.
- Write the header and the simplest case first. Stuck? UW's TAs suggest writing what you know: the method header, or a solution to part of the problem.
- Test on the question's example and one tiny edge case. On the 2025 AP 2D-array question, the point for handling a special case averaged 0.12 out of 1, the lowest on the question.
- Never leave a blank. In Stanford's 2018 handout, clear pseudocode for a correct algorithm typically earned up to half the points, but UW's CSE 121 doesn't grade pseudocode at all, so check your course's rule.
- Cross out, don't erase. Stanford's staff asked students to comment out abandoned attempts and point graders to the version they wanted graded.
- Return the value; don't print it, unless the question asks for printed output.
Frequently asked questions
Does writing code on paper actually help?
Yes, if your exam is on paper. Paper practice trains you to check code with no compiler, autocomplete or run button, which is exactly what a paper exam tests. UW's CSE 121 staff tell students to handwrite practice problems so the paper final isn't a new experience. The format itself needn't cost you: a small 2018 study of 20 novice programmers found no statistically significant difference in performance between pen-and-paper and computer exams.
How do I study for a Java exam?
Drill the four question types in Java, plus the traps Java adds: integer division, == versus equals on strings, get(i) on an ArrayList instead of square brackets, and compound conditions joined with && rather than written as 9 <= i <= 17. AP Computer Science A's free-response questions, with their scoring guidelines, are free Java practice. Write class and method headers by hand until you don't need an IDE to remember them.
How do I study for a Python exam?
Trace and write code by hand, and learn Python's own traps: range never includes its end point, / returns a float even for two integers while // rounds down, and a function that never reaches a return statement gives back None. Watch for two names pointing at one list, too; our intro CS guide shows that trap. Your course's old exams and section problems are the best practice.
Are AP Computer Science A questions good practice for a college programming final?
Yes for a Java course, as long as you know their limits. College Board describes AP CSA as equivalent to an introductory college course, and its free-response questions come with official scoring guidelines that show how partial credit works. They never ask you to write recursive code or design inheritance, and older sets don't fully match the current exam, so pair them with your own course's old exams.
Do I need to memorize syntax for a programming exam?
You need the core syntax, but not every detail. Many courses hand out a reference sheet: UW's CSE 121 provides one for its final, and Stanford's CS106A gave one for its summer final. AP graders ignore some minor slips, such as a missing semicolon where the structure is clear, but they still need every step of the algorithm in the right order. Put your hours into patterns and logic, and the syntax you use in them will stick.
How do I get partial credit on a coding exam?
Show every piece you can. Write the method header, handle the simple or empty case, and outline the rest in comments or plain English if you're stuck and your course grades pseudocode (UW's CSE 121 doesn't). AP rubrics award separate points for pieces such as headers, loops and return statements, so a partial answer can still score. Cross out an abandoned attempt instead of erasing it, and point the grader to the version you want graded.
What should I put on a programming exam cheat sheet?
Whatever you're likely to forget under pressure, not what you know cold. UW's CSE 121 TAs suggest building it early, since condensing a course onto one sheet is itself studying, and filling it with the concepts and problems you find hardest. Good candidates: the loop pattern skeletons, method names that aren't on the official reference sheet, and the mistakes from your practice log.
Sources
- AP Computer Science A Course and Exam Description — College Board, 2025
- AP Computer Science A Past Exam Questions — College Board (AP Central)
- AP Computer Science A 2026 Free-Response Questions — College Board
- AP Computer Science A 2026 Scoring Guidelines — College Board
- Chief Reader Report on Student Responses: 2025 AP Computer Science A Free-Response Questions — College Board
- Exam (CSE 121, Autumn 2026) — University of Washington, Paul G. Allen School
- CS106A Final Exam (Summer 2026) — Stanford University
- Exam Strategies (CS 106A Handout #15, 2018) — Stanford University
- Exams (CS 1110, Fall 2026) — Cornell University, Department of Computer Science
- Introduction to CS and Programming using Python (6.100L), Calendar — MIT OpenCourseWare
- More Control Flow Tools (The Python Tutorial) — Python Software Foundation
- Expressions (The Python Language Reference) — Python Software Foundation
- Polymorphism (The Java Tutorials) — Oracle
- A theory of instruction for introductory programming skills — Computer Science Education, Xie et al., 2019
- Coding by hand or on the computer? Evaluating the effect of assessment mode on performance of students learning programming — Journal of Computers in Education, Öqvist & Nouri, 2018
This guide was researched from the sources above, drafted with AI assistance and checked against those sources before it was published. Dates, deadlines and offers change: check the official page before you act. Found something wrong or out of date? Email support@getlykke.com.