Learn how computers think, what programming languages are, and how code goes from human-readable text to something a CPU can actually run.
At its core, every computer has three key parts that work together.
The brain. Performs calculations and runs instructions — billions per second. Think of it as a chef following a recipe.
Short-term memory. Super fast, but temporary — everything in RAM disappears when you turn off the computer.
Long-term memory. Slower, but permanent — where your files and programs live when not running.
The CPU repeats this cycle billions of times per second. It's fast, not smart.
A program is just a very long, very precise recipe for the computer to follow.
Just like a recipe, skip a step or do them out of order and you get something unexpected — or nothing at all!
Computers do exactly what you tell them. Bugs happen because you wrote the wrong step — not because the computer made a mistake.
Every comma, bracket, and letter counts. Programming teaches you to think clearly and precisely.
Your program never talks directly to hardware. There's a layer in between — the Operating System.
Manages CPU time, RAM, storage, and devices so multiple programs can share hardware without crashing into each other.
When Java prints to the screen, it asks the OS, which tells the display driver, which controls the monitor. Java handles this chain — you just write println().
CPUs only understand 0s and 1s — programming languages bridge the gap between humans and machines.
Created by James Gosling at Sun Microsystems to solve a big problem: code written for one OS wouldn't run on another.
Java compiles to bytecode, which the JVM (Java Virtual Machine) can run on any computer — Windows, Mac, Linux.
Android apps, Minecraft, bank systems, government software — and it's the language used in AP Computer Science A!
Different languages take different paths to the CPU. Java's approach is a middle ground — next slide we'll compare it to C and Python.
C, Python, and Java each take a completely different path from source code to running program.
Fastest at runtime. Compiles to machine code your OS runs directly. Not portable — you recompile per platform.
No compile step. The interpreter reads and runs each line. Great for quick scripts; slower at runtime than compiled languages.
Compiles once to portable bytecode. The JVM handles the final step on each platform. Best of both worlds for most use cases.
How does code actually run? Two very different approaches.
The entire program is translated before it runs. The compiler checks for errors first — nothing runs until it's clean.
✅ Catches errors early · Often faster
Instructions are read and run one line at a time as the program executes. More flexible, but errors only show up when that line runs.
✅ Easier to test · No compile step
Java makes you label what type of data a variable holds. Python figures it out on the fly.
☕ Java — Statically Typed
You must declare the type. The compiler enforces it before running.
🐍 Python — Dynamically Typed
No type labels needed. More flexible but errors show up later.
You will see all three this course. Here's what each one means.
Caught before the program runs. Java won't even create a .class file. Syntax mistakes, type mismatches.
Easiest to fix — the compiler points right at it.
The program starts, but crashes mid-run. Examples: dividing by zero, accessing something that doesn't exist.
The error message shows where it crashed.
The program runs fine and produces output — but the output is wrong. Nothing tells you something broke.
Hardest to find — requires testing and thinking.
We'll set up and run this in Lesson 4 — for now, let's read it and understand every piece.
Main.java.
You don't need to run this yet. Just understand the journey a Java program takes.
How programs remember information — and why the type of data matters.
A variable is a named slot in RAM that your program can read or change while it runs.
Name — what you call it (score, lives)
Type — what kind of data it holds
Value — the actual data inside
Use camelCase: playerScore, isGameOver. Can't start with a number. Can't use Java keywords like int or class.
That's why they're called variables. A game score starts at 0 and goes up — same box, different value each time.
Java has 8 primitive types — these four cover nearly everything you'll need.
Whole numbers. Scores, counts, ages.
⚠️ 7 / 2 gives 3, not 3.5 — decimals get chopped!
Decimal numbers. Prices, averages, measurements.
8 bytes; tiny rounding quirks at extreme precision.
Exactly two values: true or false.
Powers every if statement and loop you'll ever write.
A single character in single quotes.
Single quotes = char. Double quotes = String.
String is not a primitive — it's a class. But it's so essential it gets its own slide.
The + operator joins strings together. Mix a String with any other type and Java converts it automatically.
String is capitalized because it's a class, not a primitive. Java is case-sensitive — string won't work.
Never use == to compare Strings. Use .equals() instead. We'll cover why in Lesson 9.
Three things you'll do with every variable — understand the difference between each.
Declaration creates the box. Initialization puts something in it. Java will error if you try to use a variable before it has a value.
Writing int lives = 2; a second time causes "variable already defined." Drop the type keyword on reassignment.
println adds a newline at the end. print doesn't — useful for printing things side by side.
Same math you know — with a few programming twists.
10 / 3 gives 3 — the decimal is thrown away. Make one number a double to get 3.333.
10 % 3 = 1 because 10 ÷ 3 = 3 remainder 1. Classic use: n % 2 == 0 checks if a number is even.
+= -= *= and ++ / -- are everywhere in Java code — get comfortable with them now.
Programs become useful when they can react to the user — read what they type and decide what to do next.
Read what the user types from the keyboard.
Run different code depending on a condition.
Compare values: equal, greater, less than.
Combine conditions: AND, OR, NOT.
The Scanner class lets your program pause and wait for the user to type something.
Scanner lives in the java.util package. You must import it at the top before you can use it.
nextLine() → String
nextInt() → int
nextDouble() → double
Just like System.out sends to the screen, System.in reads from the keyboard.
The most fundamental decision-making tool in any programming language.
true.
These are the building blocks of every condition you'll ever write.
Comparison operators — return true or false
Logical operators — combine conditions
&& = AND (both), || = OR (either), ! = NOT (flip it). You read ! as "not" — so !isGameOver means "game is not over."
Putting it all together — Scanner + if/else in one small program.
Variables (int secret, int guess), Scanner to read input, and if/else to react.
The player only gets one chance. In Lesson 4 we'll add a loop so they can keep guessing until they get it right.
Can you modify it to also tell the player how far off their guess was? Hint: subtraction and Math.abs().
We'll use Terminal to create the project folder, then use mise to pin Java 21 to it.
Press ⌘ Space, type Terminal, press Enter. A black or white window with a command prompt opens.
labs is your alias for ~/Development/labs. mkdir lab1 creates this lab's folder, and cd lab1 moves you into it. Your prompt should now end with lab1.
This creates a .mise.toml file in your project folder that tells mise which Java version to use here. If Java 21 isn't installed yet, mise will install it automatically.
You should see:
If you see a different version or an error, make sure you ran cd into the project folder first.
Still in Terminal — one command opens the whole project in VS Code.
The . means "this folder." VS Code opens with lab1 loaded in the Explorer panel on the left.
In VS Code's Explorer panel (left sidebar), hover over the folder name and click the New File icon (📄). Type GuessingGame.java and press Enter.
Click inside the new file and paste the GuessingGame code from the previous slide. Save with ⌘ S.
VS Code will highlight the code with colors — that's syntax highlighting telling you the code was parsed correctly.
.mise.toml file mise created — it locks Java 21 to this project so anyone who opens it gets the right version automatically.
The Java extension adds a ▶ Run button above your main method — no terminal commands needed.
Look just above the line public static void main — VS Code shows a small ▶ Run link. Click it. VS Code compiles and runs your program automatically.
VS Code opens the integrated terminal at the bottom of the screen and runs your program there. You'll see the prompt Guess a number: — click in the terminal and type your guess.
Open the terminal with ⌃ ` and run it yourself:
CPU, RAM, Storage, the OS layer. Fetch-Decode-Execute cycle. Programming languages bridge humans and binary. C, Python, Java each take a different path to the CPU.
Variables are named RAM slots. Primitives: int, double, boolean, char. Strings concatenate with +. Integer division truncates. % gives the remainder.
Scanner reads from the keyboard. if/else if/else branches on a condition. Comparison operators produce booleans. && / || / ! combine them.
Loops (while, do-while) — and we'll finally set up Java and run real code.