Course Overview

To view the entire syllabus, click here or click to explore the full course.

AP Computer Science A

To view the entire syllabus, click here or click to explore the full course.

Unit 1: Programming Fundamentals

Students learn Java basics including variables, data types, expressions, method calls, control structures (conditionals and loops), string manipulation, and basic object usage. This unit consolidates the foundational programming concepts needed for success in computer science.

Introduction to Java Programming Textbook

Programming allows us to solve complex problems, automate tasks, and create innovative solutions. Java is a popular, versatile language used in various applications.

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

This simple program demonstrates the basic structure of a Java class and how to print output to the console.

Primitive Types and Variables Textbook

Java uses variables to store data. Primitive data types include int, double, boolean, and char.


int age = 17;
double price = 19.99;
boolean isStudent = true;
char grade = 'A';

These examples show how to declare and initialize variables of different primitive types.

Expressions and Assignment Textbook

Expressions combine variables, literals, and operators. Assignment statements store the result of an expression in a variable.


int x = 5;
int y = 3;
int sum = x + y;
int product = x * y;
double average = (x + y) / 2.0;

These examples demonstrate arithmetic expressions and how to assign their results to variables.

Compound Assignment Operators Textbook

Compound assignment operators combine an arithmetic operation with assignment, providing a shorthand notation.


int number = 10;
number += 5; // Equivalent to: number = number + 5;
number *= 2; // Equivalent to: number = number * 2;
number /= 3; // Equivalent to: number = number / 3;

These examples show how compound assignment operators can simplify code and perform operations in place.

Casting and Data Type Ranges Textbook

Casting allows conversion between different data types. Each primitive type has a specific range of values it can represent.


int intValue = 10;
double doubleValue = (double) intValue; // Casting int to double
double pi = 3.14159;
int roundedPi = (int) pi; // Casting double to int (truncates decimal)
System.out.println(Integer.MIN_VALUE); // Smallest possible int value
System.out.println(Integer.MAX_VALUE); // Largest possible int value

These examples demonstrate how to cast between different types and show how to access the minimum and maximum values for integers.

Object Instantiation Textbook

Objects are instances of classes, representing entities with properties and behaviors.


String message = new String("Hello, World!");
int length = message.length();
String upperCase = message.toUpperCase();

This example shows how to create a String object and use some of its methods.

Objects are created (instantiated) using the 'new' keyword and constructors.


Scanner input = new Scanner(System.in);
Random random = new Random();
ArrayList<String> list = new ArrayList<>();

These examples demonstrate how to create objects of different classes.

Calling Void Methods Textbook

Void methods perform actions but don't return values.


System.out.println("This is a void method");
ArrayList<String> names = new ArrayList<>();
names.add("Alice");
names.clear();

These examples show how to call void methods on different objects.

Some void methods require parameters to perform their actions.


ArrayList<Integer> numbers = new ArrayList<>();
numbers.add(5); // Adds 5 to the end of the list
numbers.add(0, 10); // Adds 10 at index 0

These examples demonstrate calling void methods with different types of parameters.

Calling Non-Void Methods Textbook

Non-void methods return values that can be used in expressions or stored in variables.


String str = "Hello";
int length = str.length();
char firstChar = str.charAt(0);
boolean startsWithH = str.startsWith("H");

These examples show how to call non-void methods and use their return values.

String Objects and Methods Textbook

Strings are immutable objects with many useful methods for text manipulation.


String s1 = "Hello";
String s2 = "World";
String s3 = s1 + " " + s2; // Concatenation
String sub = s3.substring(0, 5); // Substring
boolean equals = s1.equals("Hello"); // Comparison

These examples demonstrate various operations and methods available for String objects.

String class provides many methods for string manipulation and analysis.


String text = "Java Programming";
int length = text.length();
String lower = text.toLowerCase();
String replaced = text.replace("Java", "Python");
boolean contains = text.contains("gram");
String trimmed = "  spaces  ".trim();

These examples show some commonly used String methods and their effects.

Wrapper Classes Textbook

Wrapper classes provide object representations of primitive types with useful class methods.


Integer num1 = Integer.valueOf(5);
Double num2 = Double.valueOf(3.14);
int parsedInt = Integer.parseInt("100");
double parsedDouble = Double.parseDouble("3.14");

These examples demonstrate how to use Integer and Double wrapper classes and their methods.

Using the Math Class Textbook

The Math class provides static methods for common mathematical operations.


double absValue = Math.abs(-5.5);
double power = Math.pow(2, 3);
double squareRoot = Math.sqrt(25);
double randomNum = Math.random();
int rounded = Math.round(3.7f);

These examples show how to use various methods from the Math class.

Boolean Expressions Textbook

Boolean expressions evaluate to true or false and are used for making decisions in programs.


int x = 5, y = 10;
boolean isEqual = (x == y);
boolean isGreater = (x > y);
boolean isLessOrEqual = (x <= y);
boolean complexCondition = (x < y) && (y % 2 == 0);

These examples demonstrate various boolean expressions using comparison and logical operators.

if Statements Textbook

if statements allow programs to make decisions based on boolean conditions.


int score = 85;
if (score >= 90) {
    System.out.println("A grade");
}

This example shows a basic if statement that executes code only if the condition is true.

if-else Statements Textbook

if-else statements provide alternative code to execute when the if condition is false.


int age = 15;
if (age >= 18) {
    System.out.println("You can vote");
} else {
    System.out.println("You cannot vote yet");
}

This example demonstrates an if-else statement for two different outcomes.

else if Statements Textbook

else if statements allow checking multiple conditions in sequence.


int score = 75;
if (score >= 90) {
    System.out.println("A grade");
} else if (score >= 80) {
    System.out.println("B grade");
} else if (score >= 70) {
    System.out.println("C grade");
} else {
    System.out.println("Needs improvement");
}

This example shows how to use else if statements to handle multiple conditions.

Compound Boolean Expressions Textbook

Compound boolean expressions combine multiple conditions using logical operators.


int age = 25;
boolean hasLicense = true;
if (age >= 18 && hasLicense) {
    System.out.println("You can drive");
}

int score = 75;
boolean extraCredit = true;
if (score >= 90 || extraCredit) {
    System.out.println("You pass the class");
}

These examples demonstrate the use of AND (&&) and OR (||) operators in compound boolean expressions.

Equivalent Boolean Expressions Textbook

Different boolean expressions can be logically equivalent and produce the same results.


int x = 5;
// These conditions are equivalent
boolean condition1 = !(x > 10);
boolean condition2 = (x <= 10);

// De Morgan's Law
boolean notAandB = !(x < 0 && x > 10);
boolean notAorNotB = (x >= 0 || x <= 10);

These examples show how different boolean expressions can be logically equivalent.

Comparing Objects Textbook

Comparing objects requires understanding of reference equality vs. content equality.


String s1 = new String("Hello");
String s2 = new String("Hello");
System.out.println(s1 == s2); // false (compares references)
System.out.println(s1.equals(s2)); // true (compares content)

Integer num1 = new Integer(5);
Integer num2 = new Integer(5);
System.out.println(num1 == num2); // false
System.out.println(num1.equals(num2)); // true

These examples demonstrate the difference between using == and .equals() when comparing objects.

while Loops Textbook

while loops execute a block of code repeatedly as long as a condition is true.


int count = 0;
while (count < 5) {
    System.out.println("Count: " + count);
    count++;
}

This example demonstrates a basic while loop that prints numbers from 0 to 4.

for Loops Textbook

for loops provide a compact way to iterate a specific number of times.


for (int i = 0; i < 5; i++) {
    System.out.println("Iteration: " + i);
}

This example shows a for loop that iterates 5 times, printing the iteration number.

Developing Algorithms Using Strings Textbook

Loops are often used to process strings character by character.


String text = "Hello, World!";
int vowelCount = 0;
String vowels = "aeiouAEIOU";
for (int i = 0; i < text.length(); i++) {
    if (vowels.indexOf(text.charAt(i)) != -1) {
        vowelCount++;
    }
}
System.out.println("Vowel count: " + vowelCount);

This example demonstrates how to use a loop to count the number of vowels in a string.

Nested Iteration Textbook

Nested loops are used when we need to iterate over multiple dimensions or perform repeated operations within each iteration.


for (int i = 1; i <= 5; i++) {
    for (int j = 1; j <= 5; j++) {
        System.out.printf("%4d", i * j);
    }
    System.out.println();
}

This example uses nested loops to print a 5x5 multiplication table.

Informal Code Analysis Textbook

Analyzing code informally helps understand its behavior and identify potential issues.


int sum = 0;
for (int i = 1; i <= 10; i++) {
    if (i % 2 == 0) {
        sum += i;
    }
}
System.out.println("Sum of even numbers: " + sum);

This code calculates the sum of even numbers from 1 to 10. By analyzing it, we can determine that it will add 2 + 4 + 6 + 8 + 10, resulting in a sum of 30.

Unit 2: Object-Oriented Programming

Students learn how to create and implement complex classes and objects. This unit focuses on class design, constructors, methods, encapsulation, static vs. instance members, and object relationships without inheritance.

Anatomy of a Class Textbook

A class is a blueprint for objects, containing fields (attributes) and methods (behaviors).


public class Car {
    // Fields
    private String make;
    private String model;
    private int year;
    
    // Constructor
    public Car(String make, String model, int year) {
        this.make = make;
        this.model = model;
        this.year = year;
    }
    
    // Method
    public void startEngine() {
        System.out.println("The " + year + " " + make + " " + model + " is starting.");
    }
}

This example shows the basic structure of a class with fields, a constructor, and a method.

Constructors Textbook

Constructors initialize the state of an object when it's created.


public class Rectangle {
    private double length;
    private double width;
    
    // Default constructor
    public Rectangle() {
        this.length = 1.0;
        this.width = 1.0;
    }
    
    // Parameterized constructor
    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }
    
    // Copy constructor
    public Rectangle(Rectangle other) {
        this.length = other.length;
        this.width = other.width;
    }
}

This example demonstrates different types of constructors: default, parameterized, and copy constructor.

Documentation Textbook

Javadoc comments provide a standardized way to document classes and methods.

/**
 * Represents a simple calculator.
 * This class provides basic arithmetic operations.
 */
public class Calculator {
    /**
     * Adds two numbers.
     * @param a the first number
     * @param b the second number
     * @return the sum of a and b
     */
    public double add(double a, double b) {
        return a + b;
    }
    
    /**
     * Subtracts one number from another.
     * @param a the number to subtract from
     * @param b the number to subtract
     * @return the difference between a and b
     */
    public double subtract(double a, double b) {
        return a - b;
    }
}

This example shows how to use Javadoc comments to document a class and its methods.

Accessor Methods Textbook

Accessor methods (getters) provide controlled access to an object's private fields.

public class Student {
    private String name;
    private int age;
    
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
    
    public String getName() {
        return name;
    }
    
    public int getAge() {
        return age;
    }
}

This example demonstrates getter methods for accessing private fields of a class.

Mutator Methods Textbook

Mutator methods (setters) allow controlled modification of an object's private fields.

public class BankAccount {
    private double balance;
    
    public BankAccount() {
        this.balance = 0.0;
    }
    
    public void deposit(double amount) {
        if (amount > 0) {
            this.balance += amount;
        }
    }
    
    public void withdraw(double amount) {
        if (amount > 0 && amount <= this.balance) {
            this.balance -= amount;
        }
    }
    
    public double getBalance() {
        return this.balance;
    }
}

This example shows mutator methods (deposit and withdraw) that modify the private balance field with validation.

Writing Methods Textbook

Methods define the behavior of objects and can perform operations, return values, or modify object state.

public class Circle {
    private double radius;
    
    public Circle(double radius) {
        this.radius = radius;
    }
    
    // Method that returns a value
    public double getArea() {
        return Math.PI * radius * radius;
    }
    
    // Void method that modifies object state
    public void setRadius(double radius) {
        if (radius > 0) {
            this.radius = radius;
        }
    }
    
    // Static method that doesn't require an instance
    public static double getCircumference(double radius) {
        return 2 * Math.PI * radius;
    }
}

This example demonstrates different types of methods: instance methods returning values, void methods, and static methods.

Static Variables and Methods Textbook

Static members belong to the class rather than instances and can be accessed without creating an object.

public class MathUtils {
    public static final double PI = 3.14159;
    private static int operationCount = 0;
    
    public static double square(double x) {
        operationCount++;
        return x * x;
    }
    
    public static double cube(double x) {
        operationCount++;
        return x * x * x;
    }
    
    public static int getOperationCount() {
        return operationCount;
    }
}

// Usage:
double result = MathUtils.square(5);
System.out.println(MathUtils.PI);
System.out.println("Operations performed: " + MathUtils.getOperationCount());

This example shows the use of static variables and methods, which can be accessed without creating an instance of the class.

Scope and Access Modifiers Textbook

Scope determines where variables can be accessed, while access modifiers control visibility of class members.

public class ScopeExample {
    private int instanceVar = 10; // Instance variable
    
    public void method1() {
        int localVar = 20; // Local variable
        System.out.println(instanceVar); // Accessible
        System.out.println(localVar); // Accessible
    }
    
    public void method2() {
        System.out.println(instanceVar); // Accessible
        // System.out.println(localVar); // Not accessible (out of scope)
    }
}

class AnotherClass {
    public void someMethod() {
        ScopeExample se = new ScopeExample();
        // System.out.println(se.instanceVar); // Not accessible (private)
        se.method1(); // Accessible (public)
    }
}

This example demonstrates variable scope and access modifiers in Java.

Using this Keyword Textbook

The 'this' keyword refers to the current instance of the class and is used to differentiate instance variables from parameters or local variables.

public class Person {
    private String name;
    private int age;
    
    public Person(String name, int age) {
        this.name = name; // 'this' refers to the instance variable
        this.age = age;
    }
    
    public void printInfo() {
        System.out.println("Name: " + this.name + ", Age: " + this.age);
    }
    
    public void updateAge(int age) {
        this.age = age;
    }
}

This example shows how the 'this' keyword is used to refer to instance variables and methods within a class.

Unit 3: Data Structures and Algorithms

Students learn techniques and standard algorithms to work with collections of related data, known as data structures. They delve deeper into arrays, ArrayLists, 2D arrays, and recursion while developing algorithmic thinking skills.

Array Creation and Access Textbook

Arrays are used to store multiple values of the same type in a single variable.

// Array creation
int[] numbers = new int[5];
String[] names = {"Alice", "Bob", "Charlie"};

// Array access
numbers[0] = 10;
System.out.println(names[1]); // Prints "Bob"

// Array length
System.out.println(numbers.length); // Prints 5

This example demonstrates how to create arrays, access their elements, and use the length property.

Traversing Arrays Textbook

Array traversal involves accessing each element of an array sequentially.


int[] numbers = {1, 2, 3, 4, 5};

// Using for loop
for (int i = 0; i < numbers.length; i++) {
    System.out.println(numbers[i]);
}

// Using enhanced for loop (for-each)
for (int num : numbers) {
    System.out.println(num);
}

This example shows different ways to traverse an array, using both standard and enhanced for loops.

Enhanced for Loop for Arrays Textbook

The enhanced for loop provides a simpler syntax for iterating over arrays and collections.


String[] fruits = {"Apple", "Banana", "Cherry"};
for (String fruit : fruits) {
    System.out.println("I like " + fruit);
}

// Finding the maximum value
int[] scores = {85, 92, 78, 95, 88};
int maxScore = scores[0];
for (int score : scores) {
    if (score > maxScore) {
        maxScore = score;
    }
}
System.out.println("Highest score: " + maxScore);

This example demonstrates how to use the enhanced for loop for simple iteration and finding a maximum value.

Developing Algorithms Using Arrays Textbook

Arrays are commonly used in algorithm development for tasks like searching and sorting.

public static int linearSearch(int[] arr, int target) {
    for (int i = 0; i < arr.length; i++) {
        if (arr[i] == target) {
            return i; // Return index if found
        }
    }
    return -1; // Return -1 if not found
}

// Usage
int[] numbers = {4, 2, 7, 1, 5};
int result = linearSearch(numbers, 7);
System.out.println("Index of 7: " + result); // Prints 2

This example shows a simple linear search algorithm implemented using an array.

Introduction to ArrayList Textbook

ArrayList is a dynamic array implementation in Java that can grow and shrink in size.


import java.util.ArrayList;

ArrayList<String> list = new ArrayList<>();
list.add("Apple");
list.add("Banana");
list.add("Cherry");

System.out.println(list.size()); // Prints 3
System.out.println(list.get(1)); // Prints "Banana"
list.remove(0);
System.out.println(list); // Prints [Banana, Cherry]

This example demonstrates basic ArrayList operations like adding, accessing, and removing elements.

ArrayList Methods Textbook

ArrayList provides various methods for manipulating and accessing its elements.


ArrayList<Integer> numbers = new ArrayList<>();
numbers.add(10);
numbers.add(20);
numbers.add(30);

numbers.set(1, 25); // Replace element at index 1
System.out.println(numbers); // [10, 25, 30]

numbers.add(1, 15); // Insert at index 1
System.out.println(numbers); // [10, 15, 25, 30]

System.out.println(numbers.contains(25)); // true
System.out.println(numbers.indexOf(30)); // 3

numbers.remove(Integer.valueOf(25)); // Remove by value
System.out.println(numbers); // [10, 15, 30]

This example shows various ArrayList methods including set, add with index, contains, indexOf, and remove.

Traversing ArrayLists Textbook

ArrayLists can be traversed using loops, similar to arrays but with some differences.


ArrayList<String> fruits = new ArrayList<>();
fruits.add("Apple");
fruits.add("Banana");
fruits.add("Cherry");

// Using for loop
for (int i = 0; i < fruits.size(); i++) {
    System.out.println(fruits.get(i));
}

// Using enhanced for loop
for (String fruit : fruits) {
    System.out.println(fruit);
}

// Using forEach method (Java 8+)
fruits.forEach(System.out::println);

This example demonstrates different ways to traverse an ArrayList, including traditional for loop, enhanced for loop, and the forEach method.

Developing Algorithms Using ArrayLists Textbook

ArrayLists are useful for implementing various algorithms, especially when the size of the data structure may change.


import java.util.ArrayList;
import java.util.HashSet;

public static ArrayList<Integer> removeDuplicates(ArrayList<Integer> list) {
    HashSet<Integer> set = new HashSet<>(list);
    return new ArrayList<>(set);
}

// Usage
ArrayList<Integer> numbers = new ArrayList<>();
numbers.add(1);
numbers.add(2);
numbers.add(2);
numbers.add(3);
numbers.add(1);

ArrayList<Integer> uniqueNumbers = removeDuplicates(numbers);
System.out.println(uniqueNumbers); // Prints [1, 2, 3]

This example shows an algorithm to remove duplicates from an ArrayList using a HashSet.

Searching Textbook

Searching in ArrayLists can be done using built-in methods or custom algorithms.


ArrayList<String> names = new ArrayList<>();
names.add("Alice");
names.add("Bob");
names.add("Charlie");
names.add("David");

// Using indexOf
int index = names.indexOf("Charlie");
System.out.println("Index of Charlie: " + index); // Prints 2

// Custom binary search (assuming sorted list)
public static int binarySearch(ArrayList<String> list, String target) {
    int left = 0;
    int right = list.size() - 1;
    
    while (left <= right) {
        int mid = left + (right - left) / 2;
        int comparison = list.get(mid).compareTo(target);
        
        if (comparison == 0) return mid;
        if (comparison < 0) left = mid + 1;
        else right = mid - 1;
    }
    return -1;
}

// Usage (assume names is sorted)
int result = binarySearch(names, "Bob");
System.out.println("Index of Bob: " + result);

This example demonstrates both the built-in indexOf method and a custom binary search implementation for ArrayLists.

Sorting Textbook

ArrayLists can be sorted using the Collections.sort() method or custom sorting algorithms.


import java.util.ArrayList;
import java.util.Collections;

ArrayList<Integer> numbers = new ArrayList<>();
numbers.add(3);
numbers.add(1);
numbers.add(4);
numbers.add(1);
numbers.add(5);

// Using Collections.sort()
Collections.sort(numbers);
System.out.println("Sorted numbers: " + numbers);

// Custom sorting (selection sort)
public static void selectionSort(ArrayList<Integer> list) {
    for (int i = 0; i < list.size() - 1; i++) {
        int minIndex = i;
        for (int j = i + 1; j < list.size(); j++) {
            if (list.get(j) < list.get(minIndex)) {
                minIndex = j;
            }
        }
        Collections.swap(list, i, minIndex);
    }
}

// Usage
ArrayList<Integer> unsortedList = new ArrayList<>();
unsortedList.add(5);
unsortedList.add(2);
unsortedList.add(8);
unsortedList.add(1);
selectionSort(unsortedList);
System.out.println("Custom sorted: " + unsortedList);

This example shows how to use the built-in sort method and implements a custom selection sort algorithm for ArrayLists.

2D Array Textbook

2D arrays are arrays of arrays, used to represent tables or matrices of data.


// Creating a 2D array
int[][] matrix = new int[3][4];

// Initializing a 2D array
int[][] numbers = {
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 9}
};

// Accessing elements
System.out.println(numbers[1][2]); // Prints 6

// Getting dimensions
int rows = numbers.length;
int cols = numbers[0].length;
System.out.println("Rows: " + rows + ", Columns: " + cols);

This example demonstrates how to create, initialize, and access elements in a 2D array.

Traversing 2D Arrays Textbook

Traversing 2D arrays requires nested loops to iterate through rows and columns.


int[][] matrix = {
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 9}
};

// Using nested for loops
for (int i = 0; i < matrix.length; i++) {
    for (int j = 0; j < matrix[i].length; j++) {
        System.out.print(matrix[i][j] + " ");
    }
    System.out.println();
}

// Using enhanced for loops
for (int[] row : matrix) {
    for (int element : row) {
        System.out.print(element + " ");
    }
    System.out.println();
}

This example shows how to traverse a 2D array using both standard nested for loops and enhanced for loops.

Developing Algorithms Using 2D Arrays Textbook

2D arrays are often used in algorithms for image processing, game development, and mathematical operations.


public static int[] rowSums(int[][] array) {
    int[] sums = new int[array.length];
    for (int i = 0; i < array.length; i++) {
        int sum = 0;
        for (int j = 0; j < array[i].length; j++) {
            sum += array[i][j];
        }
        sums[i] = sum;
    }
    return sums;
}

// Usage
int[][] matrix = {
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 9}
};

int[] rowSums = rowSums(matrix);
for (int sum : rowSums) {
    System.out.println("Row sum: " + sum);
}

This example demonstrates an algorithm to calculate the sum of each row in a 2D array.

Recursion Textbook

Recursive methods are methods that call themselves to solve problems by breaking them down into smaller, similar subproblems.


public static int factorial(int n) {
    if (n == 0 || n == 1) {
        return 1; // Base case
    } else {
        return n * factorial(n - 1); // Recursive case
    }
}

// Usage
System.out.println("Factorial of 5: " + factorial(5)); // Prints 120

This example shows a recursive method to calculate the factorial of a number.

Recursive Searching and Sorting Textbook

Recursion can be used to implement searching and sorting algorithms.


public static int binarySearch(int[] arr, int target, int low, int high) {
    if (low > high) {
        return -1; // Element not found
    }
    
    int mid = (low + high) / 2;
    if (arr[mid] == target) {
        return mid; // Element found
    } else if (arr[mid] > target) {
        return binarySearch(arr, target, low, mid - 1); // Search left half
    } else {
        return binarySearch(arr, target, mid + 1, high); // Search right half
    }
}

// Usage
int[] numbers = {1, 3, 5, 7, 9, 11, 13, 15};
int target = 7;
int result = binarySearch(numbers, target, 0, numbers.length - 1);
System.out.println("Index of " + target + ": " + result); // Prints 3

This example demonstrates a recursive implementation of the binary search algorithm.

Recursive Backtracking Textbook

Recursive backtracking is a technique used to solve problems by trying out different possibilities and undoing choices that don't lead to a solution.


public class MazeSolver {
    private static final int WALL = 1;
    private static final int PATH = 0;
    private static final int VISITED = 2;
    
    public static boolean solveMaze(int[][] maze, int x, int y) {
        // Check if we've reached the exit (bottom-right corner)
        if (x == maze.length - 1 && y == maze[0].length - 1) {
            return true;
        }
        
        if (isValid(maze, x, y)) {
            // Mark as visited
            maze[x][y] = VISITED;
            
            // Try moving right
            if (solveMaze(maze, x + 1, y)) {
                return true;
            }
            
            // Try moving down
            if (solveMaze(maze, x, y + 1)) {
                return true;
            }
            
            // If neither worked, backtrack
            maze[x][y] = PATH;
        }
        return false;
    }
    
    private static boolean isValid(int[][] maze, int x, int y) {
        return x >= 0 && x < maze.length && y >= 0 && y < maze[0].length && maze[x][y] == PATH;
    }
}

This example shows how to use recursive backtracking to solve a simple maze problem.

Unit 4: Computing Systems and Networks

NEW CONTENT FOR 2025-26: Students learn to read and process data from text files using Scanner and File classes. This unit introduces file I/O operations, data set analysis, and basic computing systems concepts.

Reading Text Files with Scanner Textbook

The Scanner class can be used with File objects to read data from text files line by line or token by token.


import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class FileReader {
    public static void main(String[] args) {
        try {
            File file = new File("data.txt");
            Scanner scanner = new Scanner(file);
            
            while (scanner.hasNext()) {
                String line = scanner.nextLine();
                System.out.println(line);
            }
            
            scanner.close();
        } catch (FileNotFoundException e) {
            System.out.println("File not found: " + e.getMessage());
        }
    }
}

This example demonstrates how to read a text file using the Scanner class with proper exception handling.

Essential Scanner Methods for File I/O Textbook

Students must know these specific Scanner methods for the AP exam:


// Required Scanner methods for AP exam:

// int nextInt() - returns the next int read from the file
int number = scanner.nextInt();

// String nextLine() - returns the next line of text as a String
String line = scanner.nextLine();

// boolean hasNext() - returns true if there is a next item to read
while (scanner.hasNext()) {
    // Process next item
}

// Additional useful methods:
// boolean hasNextInt() - checks if next token is an integer
// double nextDouble() - reads next double value
// String next() - reads next token (word)

These methods are essential for reading different types of data from files and will be tested on the AP exam.

Processing Data Sets from Files Textbook

Students learn to read structured data from files and perform analysis.


import java.io.File;
import java.util.Scanner;
import java.util.ArrayList;

public class DataProcessor {
    public static void processStudentGrades(String filename) {
        ArrayList<Double> grades = new ArrayList<>();
        
        try {
            File file = new File(filename);
            Scanner scanner = new Scanner(file);
            
            // Skip header line if present
            if (scanner.hasNextLine()) {
                scanner.nextLine(); // Skip header
            }
            
            // Read grade data
            while (scanner.hasNextDouble()) {
                double grade = scanner.nextDouble();
                grades.add(grade);
            }
            
            // Calculate average
            double sum = 0;
            for (double grade : grades) {
                sum += grade;
            }
            double average = sum / grades.size();
            
            System.out.println("Average grade: " + average);
            scanner.close();
            
        } catch (Exception e) {
            System.out.println("Error processing file: " + e.getMessage());
        }
    }
}

This example shows how to read numerical data from a file and perform basic statistical analysis.

Text File Analysis Textbook

Students learn to analyze text files for patterns, word counts, and data extraction.


import java.io.File;
import java.util.Scanner;
import java.util.HashMap;

public class TextAnalyzer {
    public static void analyzeText(String filename) {
        HashMap<String, Integer> wordCount = new HashMap<>();
        
        try {
            File file = new File(filename);
            Scanner scanner = new Scanner(file);
            
            while (scanner.hasNext()) {
                String word = scanner.next().toLowerCase();
                // Remove punctuation
                word = word.replaceAll("[^a-zA-Z]", "");
                
                if (!word.isEmpty()) {
                    wordCount.put(word, wordCount.getOrDefault(word, 0) + 1);
                }
            }
            
            // Find most common word
            String mostCommon = "";
            int maxCount = 0;
            for (String word : wordCount.keySet()) {
                if (wordCount.get(word) > maxCount) {
                    maxCount = wordCount.get(word);
                    mostCommon = word;
                }
            }
            
            System.out.println("Most common word: " + mostCommon + " (" + maxCount + " times)");
            scanner.close();
            
        } catch (Exception e) {
            System.out.println("Error analyzing file: " + e.getMessage());
        }
    }
}

This example demonstrates text analysis techniques including word counting and frequency analysis.

Data Set Processing with ArrayLists Textbook

Combining file I/O with ArrayList processing for data analysis tasks.


import java.io.File;
import java.util.Scanner;
import java.util.ArrayList;

public class SalesAnalyzer {
    public static void analyzeSalesData(String filename) {
        ArrayList<Double> sales = new ArrayList<>();
        
        try {
            File file = new File(filename);
            Scanner scanner = new Scanner(file);
            
            // Read sales data from CSV file
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                String[] parts = line.split(",");
                if (parts.length >= 2) {
                    try {
                        double amount = Double.parseDouble(parts[1]);
                        sales.add(amount);
                    } catch (NumberFormatException e) {
                        // Skip invalid lines
                    }
                }
            }
            
            // Analysis
            double total = 0;
            double max = sales.get(0);
            double min = sales.get(0);
            
            for (double sale : sales) {
                total += sale;
                if (sale > max) max = sale;
                if (sale < min) min = sale;
            }
            
            System.out.println("Total sales: $" + total);
            System.out.println("Average sale: $" + (total / sales.size()));
            System.out.println("Highest sale: $" + max);
            System.out.println("Lowest sale: $" + min);
            
            scanner.close();
            
        } catch (Exception e) {
            System.out.println("Error processing sales data: " + e.getMessage());
        }
    }
}

This example shows how to process CSV data from files and perform comprehensive data analysis.

Computing Systems Overview Textbook

Students learn about basic computer systems architecture and how programs execute.


// Understanding how Java programs execute:
// 1. Source code (.java files) written by programmer
// 2. Compiled to bytecode (.class files) by javac compiler
// 3. Bytecode executed by Java Virtual Machine (JVM)
// 4. JVM manages memory, handles I/O operations

// Memory management concepts:
// - Stack: stores method calls and local variables
// - Heap: stores objects and instance variables
// - Garbage collection: automatic memory cleanup

Students should understand the basic architecture of computing systems and how Java programs are compiled and executed.

Networks and Data Transmission Textbook

Basic understanding of how computers communicate over networks.


// Network concepts students should understand:
// - Client-server model
// - IP addresses and domain names
// - HTTP protocol basics
// - Data packets and transmission
// - Security considerations (encryption, authentication)

// Example: Understanding file downloads
// 1. Client requests file from server
// 2. Server locates and prepares file
// 3. File transmitted in packets over network
// 4. Client receives and reassembles packets
// 5. File saved to local storage

Students should have a basic understanding of networking concepts and how data moves across networks.

IB Computer Science

Introduction to Programming in Java with Karel the Dog

In this module, students learn the basics of java commands, control structures, and problem solving by solving puzzles with Karel.

Topics Covered

  • Basic programming concepts
  • Control structures
  • Problem-solving strategies
  • Algorithm development

Design Thinking

This module introduces students to the theory and practice of user centered design. Students learn about what makes an engaging and accessible product and will employ an iterative design process including rapid prototyping and user testing to design and develop their own product.

Topics Covered - Topic 1.1

  • User-centered design principles
  • Iterative design process
  • Rapid prototyping techniques
  • User testing methodologies

Project: Put it in Writing!

In this project, students develop a training policy that informs employees on matters of network security and details the company policy on preventative measures employees should take.

Topics Covered - Topic 1.1

  • Network security policies
  • Employee training documentation
  • Preventative security measures
  • Policy development and implementation

Digital Information

Students learn about the various ways to represent information digitally including number systems, encoding data, programmatically creating pixel images, comparing data encodings.

Topics Covered

  • Number systems and conversion
  • Data encoding methods
  • Digital image representation
  • Data compression techniques

Networking - Topic 3.1

Students explore the structure and design of the internet, and how this design affects the reliability of network communication, the security of data, and personal privacy.

Topics Covered

  • Internet structure and protocols
  • Network communication reliability
  • Data security in networks
  • Privacy considerations

Computer Organization

Students learn about the physical elements of computers and networking, such as motherboards, RAM, routers, and the use of port numbers, ethernet, and wireless devices.

Topics Covered - Topic 2.1

  • Computer hardware components
  • Memory systems and storage
  • Network hardware and infrastructure
  • Communication protocols and standards