Unit 1 · 15 min
1.1 Introduction to Algorithms, Programming, and Compilers
A program is an algorithm written in a language the computer can check and run.
Summary, objectives and course and exam description (CED) codes
An algorithm is a step-by-step process for completing a task or solving a problem, and sequencing means its steps run in a set order, one at a time. A program is an algorithm written in Java: the compiler checks it for some errors before it can run. Programs can have syntax errors, logic errors and run-time errors such as exceptions.
By the end of this session you can
- 1.1.A Represent patterns and algorithms found in everyday life using written language or diagrams.
- 1.1.B Explain the code compilation and execution process.
- 1.1.C Identify types of programming errors.
Reviewed against the CED on
1LearnThe notes, the traps and how to remember them
1. Algorithms and sequencing
An algorithm is a step-by-step process for completing a task or solving a problem. You can represent an algorithm in written language (plain words) or as a diagram, for example a flowchart 1.1.A.1.
Here is an everyday algorithm in written language:
- Boil water.
- Put a tea bag in a cup.
- Pour in the water.
- Wait 3 minutes.
- Remove the bag.
As a flowchart, each step is a box, and arrows join the boxes in this order: boil water, then tea bag in cup, then pour, then wait, then remove the bag.
Sequencing defines the order in which the steps happen. Steps are completed one at a time 1.1.A.2. Change the order and you may change the result: swap steps 1 and 3 and you get cold, wet tea leaves.
A Java program is an algorithm too. The statements in main run in sequence, top to bottom, one at a time:
int score1 = 80;
int score2 = 90;
int score3 = 85;
int total = score1 + score2 + score3;
System.out.println("Total: " + total);
System.out.println("Average: " + total / 3);
Output:
Total: 255
Average: 85
Watch out: the total must be computed before the average. If the average line came first, total would not exist yet and the code would not compile.
2. Writing, compiling and running code
Code can be written in any text editor. However, programmers often use an integrated development environment (IDE), because it gives tools to write, compile and run code in one place 1.1.B.1. Without an IDE, you run the compiler and then the program yourself.
A compiler checks your code for some errors. Errors the compiler can detect must be fixed before the program can run 1.1.B.2.
The path from code to a working program has four stages. Each type of error shows up at a different stage:
| Stage | What happens | Error that shows up here |
|---|---|---|
| 1. Write code | You type the program in a text editor or IDE. | |
| 2. Compile | The compiler checks some errors. | Syntax error: rules broken; fix it, then compile again. |
| 3. Run | The statements execute. | Run-time error: for example an exception; the program stops abnormally. |
| 4. Test | You try known inputs and compare with the expected outcome. | Logic error: the program runs, but gives a wrong result. |
Here the programmer forgot a semicolon:
// does not compile
public class Lives
{
public static void main(String[] args)
{
int lives = 3
System.out.println(lives);
}
}
Real view: the compiler stops and reports the file, the line number (6) and the problem. Nothing runs.
Lives.java:6: error: ';' expected
int lives = 3
^
1 error
3. The three types of programming error
| Error | What it is | Who or what finds it | Example |
|---|---|---|---|
| Syntax error | The rules of Java are not followed 1.1.C.1. | The compiler | A missing ; or ) |
| Logic error | The algorithm or program is wrong, so it behaves incorrectly or unexpectedly 1.1.C.2. | Testing with specific data and comparing to the expected outcome | Area computed as length + width |
| Run-time error | Happens while the program runs (during execution); usually makes it stop abnormally 1.1.C.3. | Shows up during execution | Dividing an int by 0 |
A logic error compiles and runs without complaint. This program should print the area of a 5 by 3 rectangle, which is 15:
int length = 5;
int width = 3;
int area = length + width;
System.out.println("Area: " + area);
Output:
Area: 8
The output is wrong because the formula is wrong. Testing with data where you already know the answer (5 and 3 give 15) reveals the error. The fix is length * width.
Watch out: “it compiles” does not mean “it is correct”.
4. Exceptions
An exception is a type of run-time error. It happens because of an unexpected problem that the compiler did not detect, and it interrupts the normal flow of the program’s execution 1.1.C.4. In this course, an exception stops the program, so the statements after it do not run.
int total = 12;
int count = 0;
System.out.println("Start");
System.out.println(total / count);
System.out.println("End");
Output:
Start
Exception in thread "main" java.lang.ArithmeticException: / by zero
The code compiles, because the compiler does not know that count will be 0. The program prints Start, then stops at the division. End is never printed.
Unit 1 names three exceptions:
ArithmeticException: an integer divided by the integer zero (topic 1.3).NullPointerException: a method called onnull(topic 1.14).StringIndexOutOfBoundsException: an index outside aString(topic 1.15).
Background (not tested): what the compiler actually makes. The Java compiler turns your
.javafile into bytecode (a.classfile). The Java Virtual Machine (JVM) then runs the bytecode, which is why the same Java program runs on different operating systems. Every program starts running at its main method:public static void main(String[] args). Programmers use these words often; the exam does not test them.
5. Unit 1 on the AP® exam
- The College Board weights Unit 1 at 15 to 25 percent of the multiple-choice section. That section has 42 questions in 90 minutes and is 55 percent of the exam score.
- Unit 1 skills also appear in the free-response section (4 questions, 90 minutes, 45 percent). Question 1, Methods and Control Structures, has a part (3 points) that requires calling
Stringmethods, and the sample free-response Questions 1, 3 and 4 in the official Course and Exam Description (CED) all use Unit 1 objectives. - The unit develops 9 skills: 1.A (design), 2.A, 2.B, 2.C (develop code), 3.A, 3.C, 3.D (analyze code) and 4.A, 4.B (document code).
- Topic 1.15 (String Manipulation) is the largest topic in the unit.
- You get the Java Quick Reference on the exam. Learn the
MathandStringmethods on it now (topics 1.11 and 1.15). - Tags like 1.3.C on these pages point to the College Board learning objective each note covers. Background boxes help you understand a topic; their wording is not tested.
Official practice: do the CED sample multiple-choice Questions 1 to 4 (Exam Information section of the AP® Computer Science A CED, effective Fall 2025; Questions 1 and 2 are on page 149, Questions 3 and 4 on page 150, answer key on page 170). Questions 5 to 20 test later units. Sample free-response Question 1, Methods and Control Structures (pages 161 to 163): part (b) uses Unit 1 String methods, and part (a) needs Unit 2 loops, so try the full question after Unit 2. The same goes for the 2026 Free-Response Question 1 (released exam, pages 4 to 6) on the AP® Central past exam questions page. Score yourself with the College Board’s own scoring guidelines.
Background (not tested): words you will hear. Programmers use these words every day. They are useful, but they are not the official course wording, so on the exam look for the course term.
You may hear Course term or meaning static method class method (1.10) field, property attribute (1.7); Unit 3 adds the term instance variable pass by value call by value (1.9) actual parameter / formal parameter argument / parameter (1.9) build, make an object instantiation: create an object with new(1.13)type casting, type conversion casting (1.5) bytecode, JVM, main method not in the course framework; see section 4 above operand; unary / binary operator the value an operator works on; an operator with one / two operands (1.3) crash; bug run-time error; bug means any error, often a logic error (1.1) string joining concatenation (1.15) object address, pointer object reference (1.12)
Lock it in: memory hooks
- Three errors, three findersSyntax: the compiler catches it. Run-time: the running program trips on it. Logic: only your tests catch it.
- SequencingTea before water is just wet leaves: order changes the result.
- Compile, then runThe compiler is a gate: nothing runs until every error it finds is fixed.
Common misconceptions
"If the code compiles, the program is correct."
Not quite. The compiler only finds some errors. A logic error compiles and runs but gives a wrong result. Only testing with specific data reveals it.
"You need an IDE to write Java."
Not quite. Code can be written in any text editor. An integrated development environment (IDE) is popular because it puts the tools to write, compile and run code in one place.
"A program with a syntax error starts running and stops at the bad line."
Not quite. A program with a syntax error never runs. The compiler reports the error, and you must fix it before the program can run.
"The order of the steps does not matter as long as all the steps are there."
Not quite. Sequencing matters. Steps run one at a time in a set order, and changing the order can change the result.
Exam traps
- "It compiles" does not mean "it is correct". A logic error compiles and runs; only testing reveals it.
- A program with a syntax error never starts running. Errors the compiler finds must be fixed first.
- Match the error to who finds it: compiler for syntax, testing for logic, execution for run-time.
2PracticeRecall it, then check yourself
In 30 seconds
- An algorithm is a step-by-step process; you can write it in plain words or draw it as a diagram such as a flowchart.
- Sequencing: steps happen in a set order, one at a time.
- Any text editor works for code, but an IDE gives tools to write, compile and run in one place.
- The compiler checks for some errors, and those errors must be fixed before the program can run.
- Syntax errors break the language rules (compiler finds them), logic errors give wrong results (testing finds them), run-time errors happen during execution.
- An exception is a run-time error the compiler did not detect; it interrupts the normal flow of the program.
Cover this list, say the points out loud, then take the checkpoint without scrolling back up.
Checkpoint · 4 questions
Checkpoint: Introduction to Algorithms, Programming, and Compilers
Pick an answer to mark it. Every answer is explained, and you can try any question again. Your saved score counts first tries only, and stays in this browser.
-
Steps, in no particular order Step Action I Divide the total by 3. II Read the three scores. III Add the three scores. IV Display the result. -
Three programs with a problem Program Problem I A program prints the area of a rectangle as length + width. It runs without stopping. II A statement is missing its closing parenthesis. III A program stops abnormally when it divides an int total by an int count of 0.
3PrevailLock it in for exam day
By the numbers
- Types of programming error three errors CED 1.1.C
- syntax errorfound by the compiler
- logic errorfound by testing
- run-time errorshows up during execution
- Exceptions named in Unit 1 three exceptions CED 1.1.C.4
- Unit 1 topics (15 to 25 percent of the multiple-choice section) 15 topics CED 1.1 to 1.15
- 1.1
- 1.2
- 1.3
- 1.4
- 1.5
- 1.6
- 1.7
- 1.8
- 1.9
- 1.10
- 1.11
- 1.12
- 1.13
- 1.14
- 1.15
- Skills Unit 1 develops nine skills CED Unit 1
- 1.A
- 2.A
- 2.B
- 2.C
- 3.A
- 3.C
- 3.D
- 4.A
- 4.B
Key terms: flip the cards
Read the term, say the definition out loud, then flip to check. Struggling a little to remember is what makes it stick.
-
Algorithmtap to flip
A step-by-step process for completing a task or solving a problem, written in words or drawn as a diagram such as a flowchart.
Example and CED codes -
Sequencingtap to flip
The order in which the steps of an algorithm are completed: one at a time, in a set order.
Example and CED codes -
Integrated development environment (IDE)tap to flip
A program that gives a programmer tools to write, compile and run code in one place.
Example and CED codes -
Compilertap to flip
A program that checks code for some errors before it can run. Errors the compiler finds must be fixed first.
Example and CED codes -
Syntax errortap to flip
A mistake where the rules of the programming language are not followed. The compiler detects it.
Example and CED codes -
Logic errortap to flip
A mistake in the algorithm or program that makes it behave incorrectly or unexpectedly. Testing with specific data detects it.
Example and CED codes -
Run-time errortap to flip
A mistake that occurs while the program is running. It typically makes the program stop abnormally.
Example and CED codes -
Exceptiontap to flip
A run-time error caused by an unexpected problem the compiler did not detect. It interrupts the normal flow of execution.
Example and CED codes -
ArithmeticExceptiontap to flip
The exception thrown when a program tries to divide an integer by the integer zero.
Example and CED codes
Questions students ask
What is an algorithm in AP® Computer Science A?
An algorithm is a step-by-step process for completing a task or solving a problem. It can be written in plain language or shown as a diagram, such as a flowchart.
What is the difference between a syntax error and a logic error?
A syntax error breaks the rules of Java, so the compiler finds it and the program cannot run. A logic error follows the rules, so the program runs, but the algorithm is wrong and the result is wrong. Testing finds logic errors.
Is an exception a compile-time error?
No. An exception is a type of run-time error. It happens while the program runs, because of a problem the compiler did not detect, and it interrupts the normal flow of execution.
Do I need an IDE for the AP® exam?
No. On the exam you write and read code on paper or screen without running it. An IDE is a helpful tool for practice because it lets you write, compile and run code in one place.