Start here
How the Machine Thinks
Before you write a line of Java, you should know what a computer actually is: switches, numbers built out of switches, and a set of tools that will not think for you.
Every check for understanding filed under this unit, and where each one stands with your classes. The whole console →
- Bits, bytes and F checking
- Who has your code? checking
This unit is not on the AP exam. It is here because everything that is on the exam makes more sense once you know what is happening underneath, and because the habits you build in the first two weeks are the ones you will still have in May.
Three things to get done here. Know what the machine is. Set up the tools. Decide how you are going to work.
Gates: how switches make a decision
There is no magic layer. At the bottom, a computer is millions of switches that are either on or off. Everything above that is a story we tell about patterns of switches: numbers, letters, images, this page.
A switch that is on or off is not yet thinking. Thinking starts when the state of one switch depends on others. Watch that happen with no electricity in it at all — water poured into dishes shaped so it only makes it through under certain conditions. The dish is the logic.
Those dishes have names, and there are only a few:
- AND outputs 1 only when both inputs are 1.
- OR outputs 1 when either input is 1.
- XOR (exclusive or) outputs 1 when the inputs are different. One or the other, but not both.
- NOT flips its single input.
Nothing in that video knows anything. It is shaped metal and gravity. Which raises the question this whole unit is really about.
How can wires and electricity think?
One gate, one light
Two wires in. The gate lets current through only when both are live — that is an AND, and it is two transistors. Click A and B. When the bulb lights, a piece of metal just made a decision.
Scroll. It starts with two wires.
That climb — voltage, switch, gate, adder, chip — is one whole field of study, Computer Engineering, compressed into five scroll-lengths. If it grabbed you, go and take that course; there is a lifetime of work in any one of those stops. What matters here is only that you have seen it, because everything above it is what we spend the year on, and it is much easier to trust a floor you have looked at.
So what is thinking?
Nothing you just scrolled through thinks. Every stop on that climb is a mechanism dumb enough to be completely reliable, and the arrangement is the part a person supplied. What we call thinking is what a few billion reliable dull steps look like from far enough away.
This has a practical consequence you will feel by October. The machine does exactly what you said, at every level, without judgment or interpretation. When your program is wrong, the machine is not confused and it is not being difficult. Somewhere in the arrangement you made a promise you did not mean. Debugging is finding the promise.
The ladder of abstraction
Subject: a program adding two numbers
Climb it. Same subject, 8 heights.
Top rung
int total = a + b;
One line you can read aloud, standing on all seven rungs below it. It runs on the JVM — the imaginary machine the bytecode was written for — which is shipped inside the JRE, the runtime you install to RUN Java. The JDK is the JRE plus javac, which is why you need the JDK to write Java and only the JRE to run it. Every rung was built so the one above it could stop thinking about the one below.
High
iload_1, iload_2, iadd
What javac produces. Instructions for a machine that does not physically exist, which the JVM turns into instructions for the one that does.
Middle
macOS, Windows, Linux.
One processor, many programs. The OS decides whose turn it is, hands each one a private-looking slice of memory, and owns the keyboard, the disk and the network so no program has to. Your code never touches hardware — it asks the OS.
Middle
Fetch, decode, execute, repeat.
A clock ticks, and a stored number chooses which gates act. Now instructions exist.
Middle
XOR plus AND adds two bits. Two gates in a loop remember one.
Arithmetic and memory, out of the same parts. Nothing was added except arrangement.
Low
AND, OR, XOR, NOT.
Two or three transistors arranged so the output depends on the inputs in one fixed way. The water dishes in the video.
Low
A switch that a wire can flip.
The one component that makes the rest possible, because it is controlled by the same stuff it controls.
Bottom rung
About 1 volt, or about 0.
Physics. No meaning at all yet. A level on a wire, which we have agreed to read as 1 or 0.
Each layer exists so the layer above it can ignore the layer below. That is what abstraction is, and it is the reason you can write Java without owning a soldering iron. It is also CED topic 3.1, which you will meet again when you start designing your own classes.
— The layers between a voltage and a variable
What the processor is actually doing
Everything below this rung is arrangement. The processor is the first rung that does something over time — and it only ever does one thing, on a loop, a few billion times a second.
-
Fetch
Get the next number
A counter says which memory cell. Read it. Add one to the counter.
-
Decode
What does it mean?
The number IS the instruction. Its bits pick which gates get to act.
-
Execute
Let those gates act
Add. Compare. Store. One tick of arrangement doing its job.
Then again — a clock ticks and the whole thing repeats. Nothing decides to stop; the counter just keeps moving. Your laptop has been doing this since you opened the lid.
Here is the part worth sitting with. A stored number chooses which gates act. That sentence is the whole payoff of everything above it.
Up to now, an arrangement of gates could do exactly one thing forever — an adder adds, and that is all it will ever be. Feed the gates a number that selects which of them fire, and the same hardware becomes a different machine on every tick. Nothing was added. No new component. The arrangement just started taking instructions.
That is the invention. Not electricity, not transistors, not even the gate: the moment the machine’s behaviour became data you can change. Every program you will ever write is a long list of numbers chosen to steer the same few million gates through a sequence nobody built into them.
Quick check · not graded, try as many times as you like
Add this question to
Loading your meetings…
One XOR gate and one AND gate, both fed the same two bits, make a half adder. The XOR produces the sum digit. What is the AND for?
1 + 1 in binary is 0 carry 1. XOR gives you the 0 and AND gives you the 1, and there is no third component involved. Chain eight of these together and you have an adder — arithmetic assembled out of switches, which is the whole claim this unit is making.
Quick check · not graded, try as many times as you like
Add this question to
Loading your meetings…
Gates on their own forget everything the instant their inputs change. What turns a handful of gates into one bit of memory?
Cross-couple two gates and the pair has two stable states, so it stays where you put it. Memory is not a different kind of thing from logic. It is logic wired in a circle, which is the same trick that makes a loop in code able to accumulate a total.
Quick check · not graded, try as many times as you like
Add this question to
Loading your meetings…
Both inputs to an XOR gate are 1. What comes out?
XOR means exclusive or: one or the other, not both. It is the gate behind addition, since 1 + 1 in binary is 0 with a carry, and you will meet it again in Unit 2 as the difference between "or" and "either but not both."
Counting in binary
You have just watched eight gates add two numbers, so here is the notation for what they were adding.
One switch holds one bit. On or off. 1 or 0. That is the whole vocabulary. Eight bits make a byte, and a byte has 256 possible patterns, because each of the eight switches doubles the count: 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 = 256.
art wanted You already know how base ten works, you have just never had to say it out loud. In 4,207 the 7 is worth 7 ones, the 0 is worth 0 tens, the 2 is worth 2 hundreds, and the 4 is worth 4 thousands. Each place is ten times the one to its right.
Binary is the same idea with a smaller alphabet. Each place is two times the one to its right:
place value 128 64 32 16 8 4 2 1
binary 1 0 1 0 0 1 1 0
Add up the places with a 1 in them: 128 + 32 + 4 + 2 = 166.
Watch a mechanical counter do it. Every time the ones place runs out of room it flips back to 0 and pushes a carry to the left, which is exactly what happens when 9 becomes 10 in base ten.
To convert a number to binary, work down from the largest place value that
fits. For 100: does 128 fit? No, write 0. Does 64? Yes, write 1, and 36 is left.
32 fits, leaving 4. 16 and 8 do not. 4 fits, leaving 0. Nothing after that.
100 is 01100100.
Quick check · not graded, try as many times as you like
Add this question to
Loading your meetings…
What is 00011010 in decimal?
place value 128 64 32 16 8 4 2 1
binary 0 0 0 1 1 0 1 0 Add only the places holding a 1: 16 + 8 + 2 = 26. A useful habit is to write the place values above the digits every single time until you stop needing to.
Hexadecimal, and why anyone bothers
Binary is correct and unreadable. 11111111 is hard to hold in your head, and
harder to type without slipping.
Hexadecimal is base sixteen. Sixteen digits: 0 to 9, then A, B, C, D, E, F for ten through fifteen. It matters because sixteen is 2⁴, so one hex digit is exactly four bits, every time, with no arithmetic:
binary 1111 1111
hex F F -> FF = 255
binary 1010 0110
hex A 6 -> A6 = 166
That is the whole reason hex exists. It is shorthand for binary that a human can
read aloud. When you write a colour in CSS as #C4411C, you are writing three
bytes: red C4, green 41, blue 1C. When a Java stack trace shows you an
address like 0x7fae3c00, that is hex too.
| Decimal | Binary | Hex |
|---|---|---|
| 9 | 1001 | 9 |
| 10 | 1010 | A |
| 12 | 1100 | C |
| 15 | 1111 | F |
| 16 | 10000 | 10 |
| 255 | 11111111 | FF |
Quick check · not graded, try as many times as you like
Add this question to
Loading your meetings…
Why is hexadecimal used for binary rather than, say, base ten?
Ten is not a power of two, so a decimal digit would straddle bit boundaries and converting would take real division. Sixteen is 2⁴, which makes the conversion a lookup table you can memorise in an afternoon.
Your tools
Five installs, all free, all before the second class. Take them one at a time. There is nothing to tick: move to the next step and the shield above fills. It remembers, so you can install two on Tuesday and the rest on Wednesday.
Each one comes with what it actually does, because “install this editor” is not a thing worth knowing and “your editor talks to a Java compiler over a protocol designed for exactly this” is.
I am not against these tools. I use them. I am against using them first, because of what it costs you.
An autocomplete that writes a loop for you is producing something you cannot yet check. You will not notice it went one index too far, because noticing that is the skill you skipped. On the AP exam there is no autocomplete, and in the job you eventually want, the person who can tell whether generated code is right is worth ten times the person who can only generate it.
There is also a plain fact about how learning works: the struggle is not an obstacle in front of the learning, it is the learning. The minutes you spend stuck, tracing a loop on paper, wondering why the output is 3 and not 3.5, are the minutes that build the thing you are here to build. Shortcut those and you arrive in May with a folder of working programs and nothing in your head.
So: grind first. Ask me. Ask a friend. Say the problem out loud, which solves it about a third of the time on its own. Then, once you can read code and say what it does, turn the tools back on and go faster than you ever could by hand.
How you turn work in
Assignments come through GitHub Classroom. I post a link, you accept it, and GitHub makes you a private repository with the starter code in it.
After that, three verbs. They sound like the same thing. They are not, and the difference is the whole section.
-
Save
Your disk
Ctrl-S. Nothing has left the room.
-
Commit
Your history
A snapshot with a note on it. Still yours alone.
-
Push
GitHub. Me.
The only one that crosses the internet.
Sync first — before you start work, every time. It pulls down anything that changed while you were gone. Skip it and you spend Sunday night merging instead of coding.
Committed and pushed, or it did not happen.
Commit as you go, not once at the end. Five small commits tell me where you got stuck. One commit at midnight called “done” tells me nothing.
Four questions, same rule
One · not graded, try as many times as you like
Add this question to
Loading your meetings…
You hit Ctrl-S. Twelve times. Really hard. Who has your code now?
Save writes bytes to your own disk. Nothing leaves the building. The number of times you press it does not change the audience.
Two · not graded, try as many times as you like
Add this question to
Loading your meetings…
Good. Now you commit. What did that send to GitHub?
A commit is a snapshot in your repository. It is genuinely useful — it is the checkpoint you can come back to — but it is local. The internet has not been involved yet.
Three · not graded, try as many times as you like
Add this question to
Loading your meetings…
Your partner pushed on Saturday. You worked all day Sunday without opening GitHub Desktop first, and now it will not let you push. What did you skip?
Your history and theirs both claim to follow Friday. Git will not guess which one wins. Sync before you work — a thirty-second pull on Sunday morning beats an hour of merge on Sunday night.
Four · not graded, try as many times as you like
Add this question to
Loading your meetings…
It is 11:58pm. I open your repository. What am I looking at?
Three verbs, three different distances. Save reaches your disk. Commit reaches your local history. Push reaches me. Committed and pushed, or it did not happen.
Before the next unit
- VS Code installed, with Extension Pack for Java and Live Share.
- Copilot disabled.
- GitHub Desktop installed and signed in to your GitHub account.
- You can convert a byte to decimal and back without looking at the table.
Once that is true, Unit 1 starts with actual Java, and the exam framework begins.
Where you are
Not startedAnswer the checks above whenever you like. They're not graded, and you can retry any of them.
Sources
- College Board — AP Computer Science A Course and Exam Description, Effective Fall 2025
AP Computer Science A · members' unit
How the Machine Thinks is behind a locked door
Units in AP Computer Science A are for people taking the course. Getting in takes a link or a key — signing in on its own doesn't do it.
What's in this unit · 15 min read
- Gates: how switches make a decision
- How can wires and electricity think?
- Counting in binary
- Hexadecimal, and why anyone bothers
- Your tools
- How you turn work in
- Before the next unit
9 quick checksabstraction ladderstepperlogic gate scroller
1 Sign in
With your school Google account. This is how your work reaches the gradebook — it doesn't open the unit by itself.
A key unlocks this browser and keeps your progress here; signing in keeps it with you across devices. Either way the key itself is only ever checked as a hash. Manage all of this on your account, read what signing in stores, or go back to AP Computer Science A.