1. Reference Guide

Key Topics


Term Definition Example
Algorithm A step-by-step process that completes a task. The login steps below
Sequencing Doing the steps one at a time, in order. Log in before you click Send
Source code The Java program you write, saved in a .java file. StoreUserInfo.java
Compiler Checks code for syntax errors and turns it into bytecode. javac StoreUserInfo.java
Bytecode The compiled .class file that the Java Virtual Machine runs. StoreUserInfo.class
Exception A run-time error that stops the program while it runs. ArithmeticException
  • The compiler finds syntax errors before the program can run
  • Testing with answers you already know finds logic errors the compiler cannot see

Steps in Order

An algorithm is a step-by-step process for a task, like a recipe.

Making a sandwich

  1. Get two slices of bread
  2. Spread peanut butter on one slice
  3. Spread jelly on the other slice
  4. Put the slices together
  5. Cut in half

Notice how each step is clear and in a specific order. That’s an algorithm!

Types of Errors

Error When you find it Example
Syntax The compiler stops you, so the program cannot run yet. System.out.println("Hi") with no semicolon
Logic It runs, but testing shows a wrong answer. test1 + test2 / 2 divides before adding
Run-time (exception) It compiles, then stops while running. 12 / 0 throws an ArithmeticException

Login Algorithm

Code Runner Challenge

Change the values, predict the output, then run it

View IPYNB Source
1. Get username from user
2. Get password from user
3. Check if username exists in database
4. If username doesn't exist → show error message
5. If username exists → compare password
6. If password matches → grant access
7. If password doesn't match → show error message
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

From Code to Running Program

Step What happens Errors found here
1. Write You type source code in a .java file. None yet
2. Compile javac checks the rules and makes a .class bytecode file. Syntax errors
3. Run The Java Virtual Machine (JVM) runs the bytecode. Run-time errors (exceptions)
4. Test You compare the output with an answer you already know. Logic errors

Naming the Error

  • Won’t compile → syntax error
  • Compiles, then stops while running → run-time error (exception)
  • Runs, but the answer is wrong → logic error

2. LxD Cycle Process

Empathize: Students write steps that are too vague for a computer, like “Prepare for school, Go to school.” They also think code that compiles is code that works. In 37 million student compilations, the mistakes that took longest to fix were semantic, not syntax (Altadmri & Brown, 2015).

Define:

  • POV: CSA students need to put steps in order and tell syntax, logic, and run-time errors apart, because a program can compile and still give the wrong answer.
  • Learning Goal: Students will write an algorithm as ordered steps, explain how Java code is compiled and run, and name the three types of errors.

Ideate:

  • HMW Question: How might we make “it compiles” and “it works” feel like two separate checks?
  • HMW Question: How might we use an everyday routine to show why step order matters before students see code?
  • Activity: Put the steps of closing a store in order, read a login algorithm next to its Java code, then write and test your own.

Prototype:

  • A reference guide with steps in order and an error-type table, runnable Java examples, a Store Closing ordering challenge, an MCQ knowledge check, and a three-part homework with a grading rubric.
  • Students revise their step order after running the Store Closing cell and revise Part C until every test prints the right letter.
  • Excellence means writing steps specific enough for a computer to follow, naming the error type in a broken program, and improving the first attempt rather than only producing working code.

Test:

  • Ask peers in peer review to complete the practice without additional explanation.
  • Observe whether peers treat “it compiles” and “it works” as two separate checks.
  • Compare your lesson with another that is posted.
  • Use the findings to revise any instruction or rubric criterion that did not guide students clearly.
  • On submission, collect evidence from the Store Closing output, runner output, MCQ results, AI grading and student explanations.
  • After teaching, grading and analysis, come back and revise lesson to complete teaching cycle for continuous improvement.

3. College Board Requirements

AP CSA Unit 1, Topic 1.1 Introduction to Algorithms, Programming, and Compilers. Quoted from the course and exam description (College Board, 2025, pp. 30-31):

  • 1.1.A.2 “Sequencing defines an order for when steps in a process are completed. Steps in a process are completed one at a time.”
  • 1.1.B.2 “A compiler checks code for some errors. Errors detectable by the compiler need to be fixed before the program can be run.”
  • 1.1.C.2 “A logic error is a mistake in the algorithm or program that causes it to behave incorrectly or unexpectedly. These errors are detected by testing the program with specific data to see if it produces the expected outcome.”

4. Lesson Plan

Learning Objective: Write an everyday algorithm as ordered steps, explain how code is compiled and run, and identify syntax, logic, and run-time errors.

Success Criteria: You can order steps, fix an algorithm with steps out of order, turn an algorithm into code, and name the error type in a broken program.

Tech Talk (5 minutes)

An algorithm is a list of steps in order. Each step runs one at a time, so order and detail decide whether it works.

Java code is compiled before it runs. The compiler catches broken rules, but it cannot catch a wrong answer, so test with data where you know the result.

Code Runner Challenge

Run the three tests, then add a test for a user that does not exist

View IPYNB Source
int test1 = 80;
int test2 = 90;
int average = test1 + test2 / 2;   // compiles, but prints 125 instead of 85
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

5. Code Examples

A. Simple: Storing Information


Code Runner Challenge

Move the lines into the right order, then run it

View IPYNB Source
// CODE_RUNNER: Change the values, predict the output, then run it
public class StoreUserInfo {
    public static void main(String[] args) {
        // Algorithm: Store user information
        int age = 16;
        String name = "Alice";
        boolean isStudent = true;

        System.out.println("Name: " + name);
        System.out.println("Age: " + age);
        System.out.println("Is a student: " + isStudent);

        // Try changing the values and run again!
        // age = 17;
        // name = "Bob";
    }
}

StoreUserInfo.main(null);
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

B. Complex: The Login Algorithm in Java

The steps above, written as code.


Code Runner Challenge

Fill in the steps, then run it until all five tests print the right letter

View IPYNB Source
// CODE_RUNNER: Run the three tests, then add a test for a user that does not exist
import java.util.HashMap;
import java.util.Map;

public class LoginSystem {
    // Simple user database
    private static Map<String, String> userDatabase = new HashMap<>();

    static {
        userDatabase.put("alice", "password123");
        userDatabase.put("bob", "securepass");
        userDatabase.put("charlie", "mypass456");
    }

    // Login algorithm
    public static boolean login(String username, String password) {
        // Step 3: Check if username exists
        if (!userDatabase.containsKey(username)) {
            // Step 4: Handle user not found
            System.out.println("❌ Error: Username not found");
            return false;
        }

        // Step 5-7: Compare password
        if (userDatabase.get(username).equals(password)) {
            System.out.println("✅ Login successful!");
            return true;
        } else {
            System.out.println("❌ Error: Incorrect password");
            return false;
        }
    }

    public static void main(String[] args) {
        System.out.println("Test 1: Correct login");
        login("alice", "password123");

        System.out.println("\nTest 2: Wrong password");
        login("alice", "wrongpass");

        System.out.println("\nTest 3: User doesn't exist");
        login("david", "anypass");
    }
}
LoginSystem.main(null);
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

6. Hacks & Practice Tasks

Prepare your submission IPYNB

  1. Create a new notebook in your portfolio homework area: _notebooks/homework.
  2. Add one raw cell at the top with the frontmatter:
---
layout: post
codemirror: true
title: Introduction to Algorithms, Programming, and Compilers HW
categories: [Java]
lesson_language: Java
lesson_topic: Algorithms HW
lesson_part: interactive
lesson_type: lesson
permalink: /csa/unit_01/1_1-hw
author: yourGithubID
---
  1. Add code cells for the Popcorn Hack and the Homework Hack. Make sure every cell runs with visible output.
  2. Submit the link to your published page at the bottom of this page, and paste this in the description box:
Lesson: CSA 1.1 Algorithms, Programming, and Compilers
MCQ 1.1: <paste the copied result line, such as 5/6 | answers: D,A,C,B>
Popcorn: 10 store closing steps printed in order (yes/no)
Part A: <activity chosen>, <number> steps
Part B: corrected email order = <your order>
Part C: all five tests print A, B, C, D, F (yes/no)

Submission Safety Rules (Read First)

  • Label each part A, B, and C.
  • Run Part C and leave the output showing.
  • Keep the five test lines in Part C.
  • Include your MCQ score.
  • Use ## headings or smaller.

Popcorn Hack (In-Class)

2-minute challenge: the 10 steps for closing a store are out of order. Put them in order, then run the cell.

  1. Read all 10 steps first
  2. Think about what has to happen before each step
  3. Move each System.out.println line to its correct spot
  4. Run it and check that the output reads like a real closing routine

Keep all 10 steps. Only change their order.

// CODE_RUNNER: Move the lines into the right order, then run it
// Practice #1 - Store Closing Algorithm
public class StoreClosing {
    public static void main(String[] args) {
        // These 10 steps are out of order. Move each line so the store closes safely.
        System.out.println("Mop the floor");
        System.out.println("Turn on the security system and cameras");
        System.out.println("Count inventory");
        System.out.println("Lock the front door after the last customer leaves");
        System.out.println("Take out the trash");
        System.out.println("Exit through the employee door and lock it");
        System.out.println("Close out cash registers and put the money somewhere safe");
        System.out.println("Turn off all of the lights");
        System.out.println("Straighten up the items on the shelves");
        System.out.println("Make a list of items that need to be restocked");
    }
}

StoreClosing.main(null);

MCQ Check

4 questions, one at a time. Answer, check, then go to the next one. At the end, copy the score line into your submission notes.

Homework Hack

Task: Do all three parts in your submission notebook.

Part A. Write an algorithm of at least 8 specific steps, in order, for one of these: getting ready for a basketball game, making a pizza from scratch, or setting up a new phone.

Part B. These steps are out of order. Rewrite them correctly.

Algorithm: Send an Email
1. Click "Send"
2. Open email application
3. Type the message
4. Log into your account
5. Enter recipient's email address
6. Write subject line

Part C. Fill in the skeleton below until all five tests print the right letter. The rule: 90 and up is an A, 80 a B, 70 a C, 60 a D, anything lower an F.

// CODE_RUNNER: Fill in the steps, then run it until all five tests print the right letter
public class LetterGradeCalculator {
    /**
     * Calculate letter grade from three test scores
     *
     * Args:
     *     score1, score2, score3: Test scores (integers)
     *
     * Returns:
     *     grade: Letter grade (String)
     */
    public static String calculateGrade(int score1, int score2, int score3) {
        // TODO: Your code here!
        // Step 1: Add the three scores together

        // Step 2: Calculate the average

        // Step 3: Determine the letter grade using if-else if-else

        // Step 4: Return the grade

        return "?";  // Remove this when you add your code
    }

    public static void main(String[] args) {
        // Test your function!
        System.out.println("Test 1: " + calculateGrade(95, 92, 88));  // Should be 'A'
        System.out.println("Test 2: " + calculateGrade(85, 80, 82));  // Should be 'B'
        System.out.println("Test 3: " + calculateGrade(75, 70, 72));  // Should be 'C'
        System.out.println("Test 4: " + calculateGrade(65, 60, 62));  // Should be 'D'
        System.out.println("Test 5: " + calculateGrade(55, 50, 52));  // Should be 'F'
    }
}

LetterGradeCalculator.main(null);

Grading Plan (1 Point Total)

Part Points What earns the points
Popcorn 0.2 All 10 steps print in a safe order: the front door is locked first, and the employee door is locked last.
MCQ 0.2 5 or 6 correct. 0.15 for 3 or 4, 0.1 if every question was answered.
Homework Part A 0.2 Names the activity, 8 or more specific steps, in order.
Homework Part B 0.15 App opened and logged into first, Send last.
Homework Part C 0.25 The five tests print A, B, C, D, F.
Total 1.0  

Quick Validation Checklist

  • Popcorn output shows all 10 steps in order.
  • MCQ score in the notes.
  • Part A has 8 or more numbered steps.
  • Part B keeps all six steps, reordered.
  • Part C output shows A, B, C, D, F.

7. Lesson Revisions

Revision Made: Lesson authors: what you changed because of it.


8. Feedback Evidence

Feedback Received: Lesson review of CSA 1.1 to 1.4, September 29, 2026.

  • Reference Guide (strength): Starting from a sandwich recipe and a login flow before any code is a good way in for new programmers.
  • Homework Part C (fixed): The skeleton was written in Python (def, pass, print) inside a Java lesson, so the Java code runner could not run it.
  • Grading Plan (open): The MCQ row gives full credit for “5 or 6 correct,” but the MCQ only has 4 questions, so full credit is impossible. The sample score line 5/6 has the same problem.
  • Homework overlap (open): Part C is a grade calculator, and the 1.2 homework is also a grade calculator, so students do nearly the same task twice.
  • Reference Guide (fixed): There was no Key Topics table like 1.2 has, and the guide never explained how code is compiled to bytecode, even though the lesson description promises it.
  • Structure (fixed): The section order did not match the 1.2 model lesson. The Reference Guide came third, the College Board quotes sat inside the Lesson Plan, the Grading Plan was its own section, and Revisions and Feedback were combined.
  • Frontmatter (fixed): Missing keys that the 1.2 model has, including assignment_submission_type, assignment_creator_uids, and Group.

9. References

Altadmri, A., & Brown, N. C. C. (2015). 37 million compilations: Investigating novice programming mistakes in large-scale student data. In Proceedings of the 46th ACM Technical Symposium on Computer Science Education (pp. 522–527). Association for Computing Machinery. https://doi.org/10.1145/2676723.2677258

College Board. (2025). AP Computer Science A course and exam description [Effective fall 2025]. https://apcentral.collegeboard.org/media/pdf/ap-computer-science-a-course-and-exam-description-effective-fall-2025.pdf

Submit Assignment

Self-Assessment

Rate your work on this assignment, then add a short reflection. All 5 fields are required before you can submit.

Technical Excellence

Rate the technical quality of your work on this assignment — your use of tools, problem-solving, and technical growth.

1 Explore · 2 Understand · 3 Apply · 4 Analyze/Evaluate · 5 Create/Extend
Communication

Rate how clearly you communicated your work and process — explanations, documentation, and collaboration or help-seeking.

1 Beginning · 2 Developing · 3 Consistent · 4 Strong · 5 Model
Work Habits

Rate your work habits on this assignment — time management, persistence, responsibility, and follow-through.

1 Beginning · 2 Developing · 3 Consistent · 4 Strong · 5 Model
AI Orchestration

Rate how effectively you used AI tools to support your work — prompting, verifying, extending, or accelerating your development process.

1 Explore · 2 Understand · 3 Apply · 4 Analyze/Evaluate · 5 Create/Extend

This submits the code from this lesson's code runner(s) below as a Gist for automatic review. Save each runner with its 💾 button before submitting.

    Need to update a submission later? Open the submissions dashboard.