Lesson 1
Introduction to Programming

What is Programming?

Learn how computers think, what programming languages are, and how code goes from human-readable text to something a CPU can actually run.

🖥️ Hardware 💡 Concepts 🌐 Languages 🚀 Hello World
Section 1 — Hardware

What Does a Computer Actually Do?

At its core, every computer has three key parts that work together.

🧠

CPU

The brain. Performs calculations and runs instructions — billions per second. Think of it as a chef following a recipe.

RAM

Short-term memory. Super fast, but temporary — everything in RAM disappears when you turn off the computer.

💾

Storage (SSD/HDD)

Long-term memory. Slower, but permanent — where your files and programs live when not running.

🎮 Think about it: When you open a game, it travels from Storage → RAM → CPU. The CPU runs the game logic; RAM keeps the current state; Storage holds saved files.
Section 1 — Hardware

How the CPU Runs Instructions

The CPU repeats this cycle billions of times per second. It's fast, not smart.

📥 FETCH Get next instruction from RAM 🔍 DECODE Figure out what it means (add, jump...) EXECUTE Do the instruction, store the result ...repeat billions of times/sec
🤖 Key insight: Computers are fast, not smart. They mindlessly repeat this loop, doing exactly what they're told. If you write the wrong instruction — you get the wrong result.
Section 1 — Hardware

Software = A List of Instructions

A program is just a very long, very precise recipe for the computer to follow.

🍕 Pizza Recipe 1 Make the dough 2 Add sauce 3 Add toppings 4 Bake at 220°C 5 Enjoy! 🎉

📋 Programs are recipes

Just like a recipe, skip a step or do them out of order and you get something unexpected — or nothing at all!

🐛 Bugs = wrong instructions

Computers do exactly what you tell them. Bugs happen because you wrote the wrong step — not because the computer made a mistake.

🎯 Precision matters

Every comma, bracket, and letter counts. Programming teaches you to think clearly and precisely.

Section 1 — Hardware

The OS: The Middleman

Your program never talks directly to hardware. There's a layer in between — the Operating System.

Your Program (Java, Python, a game, a browser...) asks the OS for help Operating System 🪟 Windows 🍎 macOS 🐧 Linux talks to drivers & hardware Hardware 🧠 CPU ⚡ RAM 💾 Storage 🖥️ Display println() → OS → driver → screen

🧱 What the OS does

Manages CPU time, RAM, storage, and devices so multiple programs can share hardware without crashing into each other.

🤝 Why you don't have to worry

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().

Section 2 — Programming Languages

Why Do Programming Languages Exist?

CPUs only understand 0s and 1s — programming languages bridge the gap between humans and machines.

Binary 01001000 01100101 01101100 01101100... Assembly MOV EAX, 1 ADD EAX, EBX C Language int x = a + b; printf("%d", x); ☕ Java int x = a + b; System.out.println(x); ← Human readable! ← harder to read · more control easier to read · more abstraction →

☕ Java was born in 1995

Created by James Gosling at Sun Microsystems to solve a big problem: code written for one OS wouldn't run on another.

✈️ Write Once, Run Anywhere

Java compiles to bytecode, which the JVM (Java Virtual Machine) can run on any computer — Windows, Mac, Linux.

🌍 Used Everywhere

Android apps, Minecraft, bank systems, government software — and it's the language used in AP Computer Science A!

Section 2 — Programming Languages

Java: A Hybrid Approach

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.

✏️ Main.java You write this javac ⚙️ Main.class Bytecode file JVM 🖥️ JVM Translates per OS Your CPU Runs the program! 🪟 Windows 🍎 Mac 🐧 Linux "Write Once, Run Anywhere"
💡 Java doesn't compile to raw machine code (like C) and isn't interpreted line-by-line (like Python). It hits a middle point: bytecode that any machine can run as long as it has a JVM installed — "Write Once, Run Anywhere."
Section 2 — Programming Languages

How Different Languages Reach Your CPU

C, Python, and Java each take a completely different path from source code to running program.

C hello.c gcc hello.exe Native machine code ⚡ CPU Fast. But tied to one OS. Python hello.py interpreter Read line by line No compile step! ⚡ CPU Easy to run. Slower at runtime. Java Main.java javac Main.class Bytecode (portable) JVM JVM Translates per OS ⚡ CPU Portable. Middle-ground speed.

C — Native Compile

Fastest at runtime. Compiles to machine code your OS runs directly. Not portable — you recompile per platform.

Python — Interpreted

No compile step. The interpreter reads and runs each line. Great for quick scripts; slower at runtime than compiled languages.

Java — Bytecode + JVM

Compiles once to portable bytecode. The JVM handles the final step on each platform. Best of both worlds for most use cases.

Section 2 — Types of Languages

Compiled vs. Interpreted

How does code actually run? Two very different approaches.

📦

Compiled — C, Java, Go

The entire program is translated before it runs. The compiler checks for errors first — nothing runs until it's clean.

source compile binary run Output

✅ Catches errors early · Often faster

📜

Interpreted — Python, JavaScript

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.

code.py line by line Interpreter Out

✅ Easier to test · No compile step

🤔 Think: Which catches mistakes earlier — compiled or interpreted? Compiled! The compiler checks everything before a single line runs.
Section 2 — Types of Languages

Static vs. Dynamic Typing

Java makes you label what type of data a variable holds. Python figures it out on the fly.

☕ Java — Statically Typed

int score = 100; String name = "Jesus"; double price = 9.99; boolean isWinner = true; // ❌ This won't even compile: int x = "hello";

You must declare the type. The compiler enforces it before running.

🐍 Python — Dynamically Typed

score = 100 name = "Jesus" price = 9.99 is_winner = True # This is fine in Python: x = "hello" x = 42 # type changed!

No type labels needed. More flexible but errors show up later.

😤 Heads up: Java's strictness will feel annoying at first — but it catches entire categories of bugs before your program even runs. It makes you a more precise thinker.
Section 2 — Errors

The Three Types of Errors

You will see all three this course. Here's what each one means.

🚫

Compile-Time Error

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.

💥

Runtime Error

The program starts, but crashes mid-run. Examples: dividing by zero, accessing something that doesn't exist.

The error message shows where it crashed.

🤡

Logic Error

The program runs fine and produces output — but the output is wrong. Nothing tells you something broke.

Hardest to find — requires testing and thinking.

🧠 Remember: Getting errors is normal. Every programmer gets them every day. The skill is learning to read them and fix them.
Section 3 — A First Look at Java

What Java Code Looks Like

We'll set up and run this in Lesson 4 — for now, let's read it and understand every piece.

public class Main { public static void main(String[] args) { System.out.println("Hello, World!"); } }
public class Main — defines a class. All Java code lives inside a class. The file must be named Main.java.
public static void main — the entry point. Java always starts here when you run a program.
System.out.println() — prints a line to the console. Verbose? Yes. You'll type it hundreds of times and it becomes second nature!
{ } — curly braces define the boundaries of a class or method. Everything inside belongs to it.
Section 3 — A First Look at Java

From Code to Output — Conceptually

You don't need to run this yet. Just understand the journey a Java program takes.

✏️ You write Main.java javac ⚙️ Compiler produces Main.class (bytecode) JVM 🖥️ JVM runs it on your OS 🖨️ Hello, World! printed to screen
📌 Coming in Lesson 4: We'll install Java, set up our editor, and actually run this. For now the important thing is understanding what each step does — not the commands themselves.
Lesson 2 — Variables & Data Types

Variables & Data Types

How programs remember information — and why the type of data matters.

score 100 int name "Jesus" String gpa 3.8 double isWinner true boolean RAM — labeled boxes holding values
📦 Variables 🔢 Primitives 🧮 Arithmetic 🔤 Strings
Lesson 2 — Variables

What is a Variable?

A variable is a named slot in RAM that your program can read or change while it runs.

RAM score 0 lives 3 playerName "Alex" isGameOver false Each box has a name, a type, and a value

Three things every variable has

Name — what you call it (score, lives)
Type — what kind of data it holds
Value — the actual data inside

Naming rules

Use camelCase: playerScore, isGameOver. Can't start with a number. Can't use Java keywords like int or class.

Values can change

That's why they're called variables. A game score starts at 0 and goes up — same box, different value each time.

Lesson 2 — Variables

The Four Core Primitive Types

Java has 8 primitive types — these four cover nearly everything you'll need.

🔢

int

Whole numbers. Scores, counts, ages.

int score = 100; int lives = 3;

⚠️ 7 / 2 gives 3, not 3.5 — decimals get chopped!

🌡️

double

Decimal numbers. Prices, averages, measurements.

double gpa = 3.8; double price = 9.99;

8 bytes; tiny rounding quirks at extreme precision.

boolean

Exactly two values: true or false.

boolean isWinner = true; boolean gameOver = false;

Powers every if statement and loop you'll ever write.

🔤

char

A single character in single quotes.

char grade = 'A'; char init = 'J';

Single quotes = char. Double quotes = String.

Lesson 2 — Variables

The String Type

String is not a primitive — it's a class. But it's so essential it gets its own slide.

String name = "Jesus"; String greeting = "Hello, " + name; // greeting = "Hello, Jesus" String msg = "Score: " + 42; // msg = "Score: 42" // ⚠️ Watch out: String tricky = "1" + 2 + 3; // tricky = "123", not 6!

Concatenation with +

The + operator joins strings together. Mix a String with any other type and Java converts it automatically.

Capital S matters

String is capitalized because it's a class, not a primitive. Java is case-sensitive — string won't work.

Comparing Strings

Never use == to compare Strings. Use .equals() instead. We'll cover why in Lesson 9.

Lesson 2 — Variables

Declaring, Assigning & Printing

Three things you'll do with every variable — understand the difference between each.

// Declaration — reserves the box int score; // Initialization — puts a value in score = 0; // Both at once (most common) int lives = 3; // Reassignment — change the value lives = 2; // no "int" keyword again! // Print a variable System.out.println(lives); // 2 System.out.println("Lives: " + lives); // Lives: 2

Declaration vs. Initialization

Declaration creates the box. Initialization puts something in it. Java will error if you try to use a variable before it has a value.

Common mistake

Writing int lives = 2; a second time causes "variable already defined." Drop the type keyword on reassignment.

println vs. print

println adds a newline at the end. print doesn't — useful for printing things side by side.

Lesson 2 — Variables

Arithmetic Operators

Same math you know — with a few programming twists.

int a = 10, b = 3; System.out.println(a + b); // 13 System.out.println(a - b); // 7 System.out.println(a * b); // 30 System.out.println(a / b); // 3 ← not 3.33! System.out.println(a % b); // 1 ← remainder // Force decimal division: System.out.println(10.0 / b); // 3.333... // Shortcuts a += 5; // a = a + 5 → 15 a++; // a = a + 1 → 16

⚠️ Integer division

10 / 3 gives 3 — the decimal is thrown away. Make one number a double to get 3.333.

% — The Remainder

10 % 3 = 1 because 10 ÷ 3 = 3 remainder 1. Classic use: n % 2 == 0 checks if a number is even.

Shortcuts save typing

+= -= *= and ++ / -- are everywhere in Java code — get comfortable with them now.

Lesson 3 — Input & Decisions

Getting Input & Making Decisions

Programs become useful when they can react to the user — read what they type and decide what to do next.

⌨️

Scanner

Read what the user types from the keyboard.

🔀

if / else

Run different code depending on a condition.

⚖️

Comparison operators

Compare values: equal, greater, less than.

🔗

Logical operators

Combine conditions: AND, OR, NOT.

Lesson 3 — Input

Reading User Input with Scanner

The Scanner class lets your program pause and wait for the user to type something.

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter your name: "); String name = sc.nextLine(); System.out.print("Enter your age: "); int age = sc.nextInt(); System.out.println("Hi " + name + ", you are " + age + "!"); } }

import statement

Scanner lives in the java.util package. You must import it at the top before you can use it.

Reading different types

nextLine() → String
nextInt() → int
nextDouble() → double

System.in

Just like System.out sends to the screen, System.in reads from the keyboard.

Lesson 3 — Decisions

if / else if / else

The most fundamental decision-making tool in any programming language.

int score = 85; if (score >= 90) { System.out.println("A"); } else if (score >= 80) { System.out.println("B"); } else if (score >= 70) { System.out.println("C"); } else { System.out.println("Study more!"); } // Prints: B
score = 85 ≥ 90? no yes → "A" ≥ 80? print "B" yes no → ... "A"
Java checks conditions top to bottom and stops at the first one that's true.
Lesson 3 — Decisions

Comparison & Logical Operators

These are the building blocks of every condition you'll ever write.

Comparison operators — return true or false

int x = 5; x == 5 // true — equal to x != 3 // true — not equal to x > 3 // true — greater than x < 3 // false — less than x >= 5 // true — greater or equal x <= 4 // false — less or equal

Logical operators — combine conditions

int age = 17; boolean hasTicket = true; // AND — both must be true age >= 18 && hasTicket // false // OR — at least one true age >= 18 || hasTicket // true // NOT — flips true/false !hasTicket // false
🧠 Memory trick: && = AND (both), || = OR (either), ! = NOT (flip it). You read ! as "not" — so !isGameOver means "game is not over."
Lesson 3 — Mini-Project

Mini-Project: Number Guessing Game

Putting it all together — Scanner + if/else in one small program.

import java.util.Scanner; public class GuessingGame { public static void main(String[] args) { int secret = 42; Scanner sc = new Scanner(System.in); System.out.print("Guess a number: "); int guess = sc.nextInt(); if (guess == secret) { System.out.println("🎉 Correct!"); } else if (guess < secret) { System.out.println("Too low!"); } else { System.out.println("Too high!"); } } }

What this uses

Variables (int secret, int guess), Scanner to read input, and if/else to react.

What's missing?

The player only gets one chance. In Lesson 4 we'll add a loop so they can keep guessing until they get it right.

Challenge: extend it

Can you modify it to also tell the player how far off their guess was? Hint: subtraction and Math.abs().

Mini-Project Setup — Step 1 of 3

Open Terminal & Set Up Java

We'll use Terminal to create the project folder, then use mise to pin Java 21 to it.

① Open Terminal

Press ⌘ Space, type Terminal, press Enter. A black or white window with a command prompt opens.

② Jump to labs & create the lab1 folder

labs mkdir lab1 cd lab1

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.

③ Pin Java 21 to this project with mise

mise use java@21

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.

④ Confirm Java is ready

java --version

You should see:

openjdk 21.0.x 2024-...

If you see a different version or an error, make sure you ran cd into the project folder first.

Mini-Project Setup — Step 2 of 3

Open VS Code & Create the File

Still in Terminal — one command opens the whole project in VS Code.

① Open VS Code from Terminal

code .

The . means "this folder." VS Code opens with lab1 loaded in the Explorer panel on the left.

② Create GuessingGame.java

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.

③ Paste in the code

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.

lab1 — VS Code
📁 lab1
📄 GuessingGame.java
📄 .mise.toml
public class GuessingGame {
public static void main(...) {
// your code here
}
}
Notice the .mise.toml file mise created — it locks Java 21 to this project so anyone who opens it gets the right version automatically.
Mini-Project Setup — Step 3 of 3

Run It in VS Code

The Java extension adds a ▶ Run button above your main method — no terminal commands needed.

① Click ▶ Run above main

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.

② The Terminal panel opens

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.

③ Prefer the command line? That works too

Open the terminal with ⌃ ` and run it yourself:

javac GuessingGame.java java GuessingGame
Terminal (inside VS Code)
# VS Code ran this for you automatically:
~/Development/labs/lab1 $ java GuessingGame
Guess a number:
20
Too low!
Guess a number:
60
Too high!
Guess a number:
42
🎉 Correct!
🎉 Your first real Java program — running on your Mac.
Recap — Lessons 1, 2 & 3

What You've Covered

🖥️

Lesson 1 — How Computers Work

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.

📦

Lesson 2 — Variables & Data Types

Variables are named RAM slots. Primitives: int, double, boolean, char. Strings concatenate with +. Integer division truncates. % gives the remainder.

🔀

Lesson 3 — Input & Decisions

Scanner reads from the keyboard. if/else if/else branches on a condition. Comparison operators produce booleans. && / || / ! combine them.

🚀

Coming Up — Lesson 4

Loops (while, do-while) — and we'll finally set up Java and run real code.