Class prep · TJ AP Computer Science A and Data Structures

Understand the code,then justify the result.

An independent AP Computer Science A prep course with a separate Java and Data Structures extension. Build and trace Java programs, justify algorithms and choose structures under clear contracts. Every problem has a full worked solution. Built by Neil Kothari, a TJ alumnus.

$395 covers the full school year. The first module is free.

Try one. This is a test-level question from the course.

Problem 1

  • Test level
  • Multiple choice
  • No calculator
  • 4 pts

The following complete source is accepted by the compiler. What is the correct outcome category when it runs?

public class Task {
    public static void main(String[] args) {
        int divider = 0;
        System.out.println(9 / divider);
    }

}
Choose one answer

original problems, each with a worked answer
780
original problems, each with a worked answer
at test level or beyond
540
at test level or beyond
short lessons, one for every topic
60
short lessons, one for every topic
units, all open now
10
units, all open now

Free lesson

Lesson 1.1: Algorithms, Compilation and Debugging

Write steps a computer can follow exactly, see how Java turns your code into a running program, and tell the three kinds of errors apart.

Start with algorithms, compilation and debugging. Trace complete Java programs and explain the result before running the code.

Start with a question

You text a friend how to make tea: "Pour the water, boil the water, add the tea bag." Your friend follows the list exactly. They pour cold water into a mug, then boil an empty kettle. The instructions had all the right steps, but in an order that does not work.

A computer is that friend, except it never guesses what you meant. It does exactly what you wrote, in exactly the order you wrote it. That is why programmers care so much about precise steps, the order of those steps, and finding out quickly when something goes wrong.

By the end of this lesson you will be able to:

  1. Describe a task by its contract: its inputs, the values it allows, its outputs and its effects.
  2. Trace how a program's state changes step by step, and use dependency arrows to list every valid order of steps.
  3. Explain how Java source code becomes a class file and then a running program.
  4. Classify a failure as a syntax error, a runtime error or a logic error.
  5. Choose tests that can catch a mistake, and explain why passing tests is not the same as a proof.

Programs and algorithms

An algorithm is a finite, ordered list of steps that accomplishes a task. "Finite" means it has a definite end. "Ordered" means the sequence matters. You can write an algorithm in plain English, as a diagram or as code.

A program is a set of instructions that a computer can actually carry out. A program is one way to express an algorithm.

An algorithm is only useful if it is precise:

  • Each step is an action the reader (or computer) understands.
  • The data a step needs is available when that step runs.
  • The whole process reaches the intended result.

A program can be neatly formatted and still carry out the wrong algorithm. So before you write any Java, decide what should happen.

The contract comes first

The contract of a task is the exact description of what it must do. It has four parts.

PartQuestion it answersExample
InputsWhat information goes in?The number of tickets bought
Allowed valuesWhich inputs are permitted?Whole numbers from 1 to 10
OutputsWhat comes out?The total charge, printed
EffectsWhat else visibly happens?A newline after the number, a saved receipt

A request like "calculate the charge" is not finished until these details are known. Is there a fixed fee? Which ticket counts are allowed? Must the printed number end with a newline? When you trace or test a program, use the stated contract. Do not quietly swap in a more convenient one.

Some contracts allow more than one correct output. If a contract says "print both names, one per line, in either order," then two different outputs are both correct, and a fair test must accept either one.

Problem 2

  • Core
  • True or false
  • No calculator
  • 2 pts

An algorithm can use the same steps in a different order and produce a different result. Is this statement true? Consider a counter initially 5: one step adds 4 and another doubles its current value; both steps run once.

Is the statement true or false?

Problem 3

  • Core
  • Multiple choice
  • No calculator
  • 4 pts

Which claim correctly distinguishes compilation from testing?

Choose one answer

Open the rest of this lesson, free

The full lesson and all 13 of its problems, with every worked answer.

I am aI am a

Your free lesson opens right here, on this device for 30 days. We'll email you occasional TJ class prep updates. Unsubscribe anytime.

How it works

Class prep that works alongside class

A complete AP Computer Science A prep course with a separate Java and Data Structures extension. Intended for students with algebra skills who are ready to trace and write Java programs. Work alongside your school course or study the material in sequence. Each lesson starts with a concrete example, develops the idea, and shows how to check your reasoning before you try the practice.

  • Original problems in several formats: true or false, multiple choice, multi-part and free response.
  • Each one is marked core, test level or beyond.
  • Build, trace and test complete Java programs; justify algorithms and choose data structures under explicit assumptions.
  • A worked answer for every problem, ending with the mistake that most often costs points.
  • AP core lessons followed by a clearly labeled Java and Data Structures extension, with original diagrams and code examples.

What is inside

  1. 1Java Foundations, Expressions and Method Contracts6 lessons · 78 problems
  2. 2Objects, Math Utilities and Strings6 lessons · 78 problems
  3. 3Selection, Iteration and Algorithm Reasoning6 lessons · 78 problems
  4. 4Class Design, Encapsulation and Reference Semantics6 lessons · 78 problems
  5. 5Data Ethics, Arrays, Files and ArrayLists6 lessons · 78 problems
  6. 6Two-Dimensional Data, Searching, Sorting and Recursion6 lessons · 78 problems
  7. 7Java Abstraction, Recursive Design and Linked Structures6 lessons · 78 problems
  8. 8Stacks, Queues, Maps and Hashing6 lessons · 78 problems
  9. 9Trees, Ordered Maps and Heaps6 lessons · 78 problems
  10. 10Graphs, Paths and Integrated Algorithm Design6 lessons · 78 problems
The front entrance of Thomas Jefferson High School for Science and Technology
Neil Kothari, co-founder of EduAvenues

Who built it

Neil Kothari

TJHSST alumnus · Co-founder, EduAvenues · 10+ years in TJ preparation

Neil is a TJ alumnus and has spent more than a decade working with TJ students and their families. He built this course so students can connect Java programs, algorithmic reasoning, data structures and careful testing. Every problem is written for the course and every answer is checked before it goes in.

Tuition

$395for the full school year

One tuition covers every unit of the course. All 10 units are open now. The Algorithms, Compilation and Debugging lesson stays free for everyone.

  • All 10 units: 60 lessons and 780 original problems
  • A worked answer for every problem
  • Access through the end of the school year
Enroll