Lesson 1.1: Introduction to Algorithms, Programming, and Compilers | AP CSA
Lesson 1.1: Introduction to Algorithms, Programming, and Compilers
What you’ll learn in this lesson
- 1.1.A. Represent everyday patterns and processes as algorithms using written language or diagrams, and explain why sequencing matters.
- 1.1.B. Explain the role of an IDE, the compilation step, and what kinds of errors the compiler can and cannot catch.
- 1.1.C. Identify and distinguish syntax errors, logic errors, run-time errors, and exceptions, including which are caught by the compiler and which only show up later.
This lesson is part of the AP CSA Course and Exam Description (effective May 2027).
AP exam weight: Conceptual lessons appear in the MCQ section, expect 1-3 questions per lesson topic on the live exam, often as scenario or definition stems. Lesson 1.1 vocabulary (syntax error, logic error, run-time error, exception) shows up across all four units.
What is an algorithm, and what does a computer do with it?
Every time you follow a recipe, give someone directions to your house, or work through long division, you are running an algorithm. You start with an input, you follow a fixed sequence of steps, and you end up with a result. Computer science takes that same everyday idea and asks a tighter question: what is the precise, unambiguous list of steps that solves this problem, and how do we hand those steps to a machine that has zero common sense?
Definition
An algorithm is a step-by-step process for completing a task or solving a problem. Algorithms can be represented in written language, in diagrams (like flowcharts), or in a programming language. Sequencing is the part of an algorithm that defines the order in which steps are performed, one step at a time.
AP CSA is, at its core, a course about writing algorithms in Java. Before any code is involved, though, the algorithm has to exist as a clear, ordered plan. The CED is explicit about this: students should be able to represent patterns and algorithms found in everyday life, not just type Java. The reason is practical. Programmers who can’t describe their plan in plain English usually can’t describe it in Java either. They end up debugging a mental model that was never coherent to begin with.
Sequencing: one step at a time, in a specific order
Sequencing sounds obvious until you try to break it. Consider making a peanut butter sandwich. “Spread the peanut butter, take out the bread, open the jar” lists all the right ingredients but produces a mess. The same is true in code. System.out.println(name); String name = "Tanner"; uses the right pieces but compiles only if reordered. Computers execute statements one at a time, in the order written, with no ability to look ahead or guess what you meant.
Example
Algorithm for “log in to a website”: (1) open the login page, (2) type the username, (3) type the password, (4) click submit, (5) wait for the server response, (6) display the home page only if the response was successful. Swap steps 3 and 4 and the password is never entered. Swap steps 4 and 5 and the user clicks submit before there’s anything to submit. The steps haven’t changed; only the sequence has, and the sequence is what makes it work.
From algorithm to running program: writing, compiling, executing
Once you have an algorithm, you write it in a programming language. Java code can be written in any text editor, but most programmers use an integrated development environment (IDE), a single application that lets you write the code, compile it, and run it without leaving the window. Common AP CSA classroom IDEs include IntelliJ IDEA, Eclipse, BlueJ, and Replit. The CED treats the choice of IDE as classroom-dependent and not tested directly, what is tested is what the IDE does for you.
The key step is compilation. A compiler is a program that translates your Java source code into a form the machine can run, and along the way it checks the code for certain kinds of errors. If the compiler finds an error, your program does not run at all. You must fix the error first. This is one of the most important ideas in this lesson: the compiler is a gatekeeper for one class of mistakes, but it is blind to others.
Common misconception
“If my code compiles, it works.” This is wrong, and the AP exam tests it directly. The compiler only catches errors related to the rules of the Java language (missing semicolons, undeclared variables, type mismatches). A program can compile cleanly, run end-to-end, and still produce the wrong answer because the logic, the algorithm you wrote, is flawed. Successful compilation means “Java accepts this as valid Java,” not “this solves your problem.”
The four error types you must distinguish
The CED is unusually specific here. Topic 1.1.C names four error categories, and the AP exam tests whether you can place a given mistake into the right bucket. The distinctions matter because they tell you when an error will surface: at compile time, at run time, or only when you happen to test with the right input.
- A syntax error is a violation of the rules of the Java language. Missing semicolon, misspelled keyword, unclosed brace. The compiler catches every syntax error. Your program does not run.
- A logic error is a mistake in the algorithm itself. The code compiles and runs but produces wrong output. You only catch logic errors by testing with specific inputs and comparing actual output to expected output.
- A run-time error is a problem that occurs during execution. The compiler accepted the code, but something goes wrong while the program is running, usually causing it to terminate abnormally.
- An exception is a specific type of run-time error: an unexpected condition that the compiler couldn’t predict, which interrupts the normal flow of execution.
ArithmeticExceptionfrom dividing by zero andNullPointerExceptionfrom calling a method onnullare the two you’ll see most often in Unit 1.
Key insight
The compiler catches syntax errors only. Logic, run-time, and exception errors all slip past the compiler. They require running the program (and often testing with specific inputs) to surface. This is why writing test cases is part of programming, not an optional extra.
Key vocabulary
| Term | Definition |
|---|---|
| Algorithm | A step-by-step process for completing a task or solving a problem, representable in written language, diagrams, or code. |
| Sequencing | The order in which steps in a process are completed; steps run one at a time. |
| IDE | Integrated Development Environment, an application that bundles tools to write, compile, and run code in one place. |
| Compiler | A program that translates source code into a runnable form and checks for certain language-rule errors before the program runs. |
| Syntax error | A mistake that violates the rules of the programming language; detected by the compiler. The program does not run. |
| Logic error | A mistake in the algorithm that causes incorrect or unexpected behavior; detected only by testing with specific inputs. |
| Run-time error | A mistake that occurs during program execution, typically causing the program to terminate abnormally. |
| Exception | A type of run-time error caused by an unexpected condition the compiler did not detect; interrupts the normal flow of execution. |
Tier 2 Practice Check your understanding
Six questions covering the lesson concepts. On tougher questions, try predicting your answer before reading the options, it’s the best way to catch trap distractors. Mix of formats: MCQ, matching, classification, and a vocabulary cloze.
- An algorithm can be represented in written language, in a diagram, or in code, and the representation does not change whether the algorithm is correct.
- Reordering two steps in an algorithm always produces a different result.
- An algorithm only counts as “an algorithm” once it is written in a programming language; a recipe on paper does not qualify.
ArithmeticException (division by zero) or NullPointerException the moment it tries an operation the compiler couldn’t predict. A, B, and C are all accurate: compile failures block execution, syntax errors are language-rule violations the compiler catches, and clean compilation says nothing about logical correctness.
int x = 5 and the program will not compile.ArithmeticException when the user enters 0 as the divisor.Sytem.out.println with a misspelled class name and the IDE underlines it in red before running.NullPointerException the first time it encounters an empty line.Syntax error
Logic error
Run-time error
System) are caught by the compiler, so the program never runs. The two logic errors compile and run but produce wrong output: in both cases Java did exactly what was written, which wasn’t what the student meant. The two run-time errors (division by zero, null pointer) compile cleanly and execute until they hit a condition the compiler couldn’t predict.
The After-School Tutoring Scheduler
Mr. Ramirez asks two of his students, Sara and Jordan, to write a Java program that prints the names of every student signed up for after-school tutoring on a given day. The program reads names from a text file (one name per line) and prints them in the order they appear. Sara writes the program in IntelliJ, clicks Run, and IntelliJ refuses to start the program; it underlines the second-to-last line in red. Sara fixes the underline and clicks Run again; this time the program starts, prints six names, and then terminates abnormally with a message about NullPointerException. Jordan looks at the same file and notices that the file has an empty line in the middle, which is where Sara’s program crashed. Jordan rewrites the program so it skips empty lines. It now runs to completion. But Mr. Ramirez points out that one of the printed names is wrong: the program is printing every name twice.
Part A: Identify Sara’s first error
Part B: Identify Sara’s second error
NullPointerException. Which classification best describes this second error?NullPointerException is a specific type of run-time error caused by an unexpected condition (a null value being used where an object was expected) that the compiler could not detect in advance. Every exception is a run-time error. B is wrong because a logic error means wrong output, not a crash. C is wrong because the compiler does not detect this kind of problem; the code is syntactically valid. D is wrong because Java does not have a notion of a “compilation warning” that halts execution mid-program.
Part C: Structured response
In three to five sentences, explain to Mr. Ramirez why Jordan’s final program still has a problem, even though it now compiles and runs to completion without crashing. Identify what type of error this is, and explain how Jordan would have to track it down, since the compiler and the run-time will not flag it for him.
Scoring rubric
Sample full-credit response
Jordan’s program is hitting a logic error. The code compiles, so it is not a syntax error, and the program runs to completion without crashing, so it is not a run-time error or exception. The bug is in the algorithm itself, somewhere in the code Jordan is processing each name twice (perhaps an extra loop or a duplicate print statement). Because neither the compiler nor the Java run-time can know what output Mr. Ramirez expected, no automatic tool will flag this. Jordan has to test the program with a known input file, compare the printed list to the names actually in the file, and trace through his code line by line to find where the duplication happens.
Common AP exam traps
The exam predictably tests these same misconceptions year after year. Recognize them now and you’ll catch them in May.
Trap 1: “If it compiles, it works”
Successful compilation means the code follows Java’s rules, nothing more. A compiled program can still throw exceptions at run time or produce completely wrong output. The compiler is one layer of error detection, not the only layer.
Trap 2: Confusing exception with run-time error
Students often treat “exception” and “run-time error” as synonyms. An exception is a specific kind of run-time error caused by an unexpected condition the compiler did not detect. All exceptions are run-time errors, but not all run-time errors are exceptions.
Trap 3: Logic errors classified as something else
If a program compiles, runs to completion, and produces wrong output, it is still a logic error, even when the wrong output seems “weird” or “unexpected.” The exam will phrase the scenario in ways that tempt you to call it an exception. Don’t.
Trap 4: “An algorithm has to be in code”
The CED explicitly lists written language and diagrams as valid algorithm representations. A flowchart, a numbered list of steps, and a Java method are all algorithms; the form of representation has nothing to do with whether the algorithm is correct.
How real compilers find more than just syntax errors
Modern compilers and IDEs go well beyond the bare minimum the AP exam describes. Java’s compiler also performs type checking (catching mismatches like assigning a String to an int) and definite assignment analysis (refusing to compile if a local variable might be used before it’s assigned). IntelliJ and Eclipse add static analysis on top of that, flagging suspicious patterns, unused variables, methods that always return the same value, possible null dereferences, before you even hit Run. Some of these warnings catch genuine logic errors before they ever execute. None of this is on the AP exam, but it’s worth knowing that the line between “compile-time” and “run-time” is blurrier in professional tools than the CED’s clean four-category framework suggests.
This material extends beyond the AP CSA curriculum. Skip it if you’re focused on exam prep.
Deep dive: more on this topic
Java Language Specification: Introduction
Official documentation, the source-of-truth for what the Java compiler enforces.
AP CSA Vocabulary List
150+ terms with AP-exam definitions.
Unit 1 Study Guide
Full unit overview with examples and practice.
Daily Practice Question
A new AP CSA question every day, free.
Get the AP CSA daily practice question by email
Free, daily, takes 90 seconds. Built by an AP CSA teacher with a 54.5% 5-rate.
Start daily practice →Get in Touch
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
Prefer email? Reach me directly at [email protected]