Java Lessons
Learn Java through the four units of AP Computer Science A. Each topic has a reference guide, runnable examples, popcorn hacks, and a homework hack; units end with a quiz or FRQ practice. Extension lessons apply the unit to a larger program.
To run Java cells in a notebook, set up the Java kernel first (see the guides). Back to all lessons
Unit 1 - Using Objects and Methods
| Lesson | What you will learn |
|---|---|
| 1.01 Algorithms, Programming, and Compilers | What an algorithm is, how Java source code is compiled and run, and how to read compiler errors. |
| 1.02 Variables and Data Types | Declare variables with int, double, boolean, and String, use final for constants, and choose types from what the data means. |
| 1.03 Expressions and Output | Print with System.out.print and println, use escape sequences, and evaluate arithmetic expressions. |
| 1.04 Assignment Statements and Input | Assign and update variables, tell assignment apart from equality, and read input with Scanner. |
| 1.05 Casting and Range of Variables | Convert between data types and understand the limits of primitive types. |
| 1.06 Compound Assignment Operators | Use shorthand operators (+=, -=, etc.) and increment/decrement (++, --) to modify variables. |
| 1.07 Application Program Interface (API) and Libraries | Call methods from pre-built Java classes like Math and String. |
| 1.08 Documentation with Comments | Write comments to explain code and document method requirements. |
| 1.09 Method Signatures | Identify return types, method names, and parameters from method signatures to understand what a method does and what it needs. |
| 1.09 Method Signatures - Homework homework | Practice problems for method signatures, overloading, and return types. |
| 1.10 Calling Class Methods | Call static methods on class names and trace nested method calls step-by-step. |
| 1.10 Calling Class Methods - Homework homework | Practice calling static (class) methods. |
| 1.11 Math Class | Use Math.abs(), Math.pow(), Math.sqrt(), and Math.random() for calculations. |
| 1.11 Math Class - Homework homework | Practice with Math.abs, Math.pow, Math.sqrt, and Math.random. |
| 1.12 Objects - Instances of Classes | Understand that objects are instances of classes with data and methods. |
| 1.12 Objects - Homework homework | Identify classes, objects, attributes, and behaviors in a scenario. |
| 1.13 Object Creation and Storage (Instantiation) | Create objects with new and constructors, storing references in variables. |
| 1.14 Calling Instance Methods | Call methods on objects using dot notation and use their return values. |
| 1.14 Calling Instance Methods - Homework homework | Practice creating objects and calling their instance methods. |
| 1.15 String Manipulation | Create strings, concatenate them, and use methods like length(), substring(), indexOf(), and equals(). |
| Unit 1 Quiz quiz | Review questions for primitive types, objects, and methods. |
Unit 2 - Selection and Iteration
| Lesson | What you will learn |
|---|---|
| 2.01 Algorithms with Selection and Repetition | Describe everyday algorithms with steps, decisions, and repeats using words, flowcharts, and pseudocode. |
| 2.02 Boolean Expressions | Write yes or no questions in Java with the relational operators ==, !=, <, >, <=, and >=. |
| 2.03 if Statements | Make one way and two way decisions with if and if-else, and see exactly which lines run. |
| 2.04 Nested if Statements | Chain decisions with else if and put an if inside another if to handle three or more cases. |
| 2.05 Compound Boolean Expressions | Combine conditions with &&, ||, and !, follow the precedence rules, and use short circuit evaluation safely. |
| 2.06 Comparing Boolean Expressions | Prove two Boolean expressions are equivalent with truth tables and De Morgan's Laws, and compare objects correctly. |
| 2.07 while Loops | Repeat code while a condition is true, trace loop control variables, and avoid infinite and off by one loops. |
| 2.08 for Loops | Use the three part for loop header, convert between for and while, and count iterations exactly. |
| 2.09 Implementing Selection and Iteration Algorithms | Combine loops and if statements to count, sum, find extremes, test divisibility, and pull apart the digits of a number. |
| 2.10 Implementing String Algorithms | Traverse a String with a loop and substring to search, count, reverse, and build new Strings. |
| 2.11 Nested Iteration | Put a loop inside a loop to build grids and patterns, and count exactly how many times the inner body runs. |
| 2.12 Informal Run-Time Analysis | Count statement executions from loop headers, multiply nested counts, and compare which version of a loop does less work. |
| Extension - Login Tokens and Cookies with Selection and Iteration extension | Apply if statements and loops to a login flow - validate a token and search a list of cookies. |
| Unit 2 Quiz quiz | Review questions for selection and iteration. |
| Unit 2 FRQ Practice quiz | Write AP style methods that use selection and iteration, check them against built in tests, and learn what the FRQ rubric rewards. |
Unit 3 - Class Creation
| Lesson | What you will learn |
|---|---|
| 3.01 Abstraction and Program Design | Use data and procedural abstraction and break big behaviors into smaller methods to keep programs simple. |
| 3.02 Impact of Program Design | Design reliable programs that guard against bad input, and weigh their social, ethical, and intellectual property impacts. |
| 3.03 Anatomy of a Class | Break a class into instance variables, constructors, and methods, and choose public or private access for each. |
| 3.04 Constructors | Learn what Java constructors are, why they exist, and how to write one to initialize objects. |
| 3.05 Methods - How to Write Them | Read method headers, write void and returning methods, and call them to check their results. |
| 3.06 Methods - Passing and Returning References | Pass objects into methods, spot aliasing, and see why changing an object differs from reassigning its reference. |
| 3.07 Class Variables and Methods | Use class variables/methods for shared states. |
| 3.08 Scope and Access | Know where a variable is visible, spot a shadowed instance variable, and use private fields with public accessors and mutators. |
| 3.09 this Keyword | Use the this keyword to refer to the current object, resolve shadowed names, and pass the current object to methods. |
| Extension - Object State in Games extension | Use objects, encapsulation, and class variables to model game characters whose state changes, then save and load it. |
Unit 4 - Data Collections
| Lesson | What you will learn |
|---|---|
| 4.01 Ethical and Social Issues Around Data Collection | Explore how data is collected, evaluate ethical tradeoffs, and consider privacy, consent, bias, and responsible data use. |
| 4.02 Introduction to Using Data Sets | Work with data sets by identifying variables, interpreting records, and using data to answer meaningful questions. |
| 4.03 Array Creation and Access | Create one-dimensional arrays, initialize values, access elements by index, and avoid invalid array positions. |
| 4.04 Array Traversals | Learn to traverse arrays with for, while, and enhanced for loops while avoiding off-by-one bounds errors. |
| 4.05 Implementing Array Algorithms | Implement array algorithms to calculate totals, find extremes, count matches, and transform stored values. |
| 4.06 Using Text Files | Read and process text files with Java, handle lines of input, and close file resources safely. |
| 4.07 Wrapper Classes | Use wrapper classes to convert between primitive values and objects, parse data, and work with useful constants and methods. |
| 4.08 ArrayList Methods | Use ArrayList methods to add, remove, replace, access, and measure elements in a resizable collection. |
| 4.09 ArrayList Traversals | Traverse ArrayLists with index-based and enhanced for loops while safely accessing and updating collection elements. |
| 4.10 Implementing ArrayList Algorithms | Implement algorithms with ArrayLists to search, count, calculate results, and update a resizable collection. |
| 4.11 2D Array Creation and Access | Create and access two-dimensional arrays using rows and columns, and identify valid positions in a rectangular grid. |
| 4.12 2D Array Traversals | Traverse two-dimensional arrays by row and column with nested loops and visit every element in a grid. |
| 4.13 Implementing 2D Array Algorithms | Implement 2D array algorithms — traverse a grid in row-major order, search for a value and its location, accumulate sums/counts/averages, and track a running maximum while walking the array. |
| 4.14 Searching Algorithms | Implement linear search algorithms on arrays and ArrayLists — return the index of a match, search by condition instead of equality, respect a partially-filled array's true size, and reason about best/worst case. |
| 4.15 Sorting Algorithms | Trace and implement sorting algorithms that arrange array values into ascending or descending order. |
| 4.16 Recursion | Learn recursion through a mission countdown, call-stack tracing, factorial fuel calculations, and launch-code checksums. |
| 4.17 Recursive Searching and Sorting | Apply recursion to searching and sorting problems by defining base cases, smaller subproblems, and results that combine while unwinding. |
63 pages in this section.