Before the bell
You are responsible for all of this before the end of class.
- The discussion form in the I Do deck. All three sections. If you are here, this should be done.
- Your classwork. This form on the right. Section 1 before the exit ticket pops up; Section 2 past the floor.
- Today's Bench Basics activity: Trace It. It opens later in class and lives on slide 4 of this deck.
- The exit ticket. It opens 15 minutes before the bell and lives on the last slide of this deck.
The classwork form is not linked yet. Use Station View and write your answers in your lab notebook with the item labels.
Trace It: Real Java, One Line at a Time
This reading shows how to trace real Java assignment statements in a trace table, one line at a time.
From Plain Steps to Java
Two weeks ago the class wrote a store step with an arrow, as in `x ← x + 1`. Java writes the same step as `x = x + 1;`, and the symbol `=` still means store. Oracle's Java tutorial explains that `=` assigns the value on its right to the variable on its left. A line such as `int a = 3;` declares a box named a that holds an `int`, a whole number, and stores 3 in it. A trace table has a Line column, one column for each variable and an Output column. Naming the columns means finding every box the code declares, and a word such as `System` or `println` is not a box.
One Worked Example
The program below has six lines inside the standard wrapper, and those lines are numbered 1 to 6, starting with `int a = 3;`.
1public class Main { 2 public static void main(String[] args) { 3 int a = 3; 4 int b = a + 2; 5 a = b * 2; 6 b = b - a; 7 System.out.println(a); 8 System.out.println(b); 9 } 10}
10 -5
The code declares two boxes, a and b, so the table needs a column for each of them.
Line | a | b | Output 1 | 3 | | 2 | 3 | 5 | 3 | 10 | 5 | 4 | 10 | -5 | 5 | 10 | -5 | 10 6 | 10 | -5 | -5
Row 1 stores 3 in a, and the cell for b is empty because b does not exist yet. Row 2 works out `a + 2`, which is 3 + 2, and stores 5 in b. Row 3 works out `b * 2`, which is 5 × 2, and stores 10 in a. Row 4 works out `b - a` with the new value of a, which is 5 − 10, and stores −5 in b. Rows 5 and 6 print the values that a and b hold at the end, so the program prints 10 on one line and −5 on the next.
What Bench Basics Checks
On line 3, a gets 10, and the 3 is gone for good, so line 4 uses the new a and b becomes 5 − 10, which is −5. A student who still uses 3 for a on line 4 will write 2 for b, and on the bench a row with that mistake is marked "Not yet." A box holds one value at a time, and an empty cell means the box does not exist yet. In today's bench, B14 Trace It, the first job gives the columns, and jobs 2 and 4 ask the student to pick which boxes need a column before tracing them.
Sources: Oracle, Assignment, Arithmetic, and Unary Operators (n.d.); Oracle, Variables (n.d.); classroom data, B14 Trace It and the worked example run with Java 21 (2026).
Versions, Commits and History
This section explains how a builder keeps each version of a program, what a commit records, and how to read a list of commits.
Versions of a Program
A version is the state of a project at one moment. Every time a person changes a program, there is a new version, whether or not anyone kept the old one. Many people keep old versions by copying files into another folder, a habit that the book Pro Git calls common, simple and easy to get wrong. A copy of a file with a new name is a version with no record of what changed or when, because the name is the only label it has.
Version control is a system that records changes to a set of files over time, so that a person can open a specific version later. With a version control system such as Git, a builder can return the whole project to an earlier version, compare changes over time and see who made a change and when.
What a Commit Records
In version control, a commit is a saved snapshot of the whole project at one moment, with a message about the change. The Pro Git authors explain that each time a builder commits, Git takes a picture of what all the files look like at that moment and stores it. If a file did not change, Git links to the copy it already has. For this reason, a commit holds the whole project and not only the lines that changed. Git also records who made the commit and when, and it labels each commit with a code called a hash.
A commit is made on purpose, and typing a change into a file does not add that change to the record. First, the builder chooses which changes go into the next commit, and then the builder commits them and writes a message. A change that was typed and not committed is not in the history, so it cannot be opened later as a version. A Google Doc saves changes on its own as the writer types, while a commit is made on purpose by a person and labeled with a message.
Reading a History
The history is the list of commits in order. When a builder asks Git for the history, Git lists the commits with the newest one first. Any earlier version can be opened from the history, so a change that made a program worse can be undone. A folder full of renamed copies is not a history, because the names do not record the order or the reason for each copy.
The class example is a short Java program named Stops.java, which prints a number of bus stops. Its history has three commits, and Git printed it below, one commit on each line, with the short hash, the date and the message.
77408ab 2026-11-04 Start at 8 stops because the route has 8 ea027f0 2026-11-03 Count down one stop after the first print d3683b0 2026-11-02 Add Stops.java: print the number of stops
Read from the bottom up, the history runs from oldest to newest. The first commit adds Stops.java, which prints 5. The second commit makes the program count down one stop, so it prints 5 and then 4. The third commit starts the count at 8, so it prints 8 and then 7. Figure 1 shows the same three commits as a timeline from oldest to newest, with what each version prints.
Writing a Commit Message
A commit message says what changed, and a good message also says why. The Git documentation advises starting a message with one short line, no more than 50 characters, and Pro Git adds that the reason for the change belongs in the message. For example, "Start at 8 stops because the route has 8" tells a reader what changed and the reason for it. The message "update" is not an example of a useful message, because it would fit any commit. A longer message is not always a better one, since a long message that never names the change tells a reader nothing more.
The three files in the Board Question show the problem that version control solves, because their names carry no dates, no order and no reasons. In Java, the copies cause a second problem, because a file named Stops2.java that holds the class Stops will not compile. A public class has to be in a file with the same name, and when the class example was tried this way, javac reported an error saying that class Stops belongs in a file named Stops.java.
Summary
A version is the state of a project at one moment, and version control records versions so that any of them can be opened later. A commit is a saved snapshot of the whole project with a message about the change, and a person makes it on purpose. The history lists the commits in order, and a useful commit message says what changed and why.
Sources: Chacon and Straub, Pro Git, 2nd ed., sections 1.1, 1.3, 2.2, 2.3 and 5.2 (2014); Git project, git-commit Documentation (n.d.); Git project, git-log Documentation (n.d.); Google, Create, view, or download a file (n.d.); classroom data, the Stops example repository (2026).
The classwork form is not linked yet. Use Station View and write your answers in your lab notebook with the item labels.
MC 1. According to the passage, what does a commit save?
- Only the lines that changed since the commit before it
- A snapshot of the whole project at one moment, with a message about the change
- Every key the builder typed while the file was open
- A list of the people who are allowed to open the project
MC 2. Git records several things with each commit. Which one does the person making the commit write?
- The date and time when the commit was made
- The hash that labels the commit in the history
- A copy of every file that did not change
- The message about the change
MC 3. Git printed this history for a program named Score.java. Which commit is the newest?
dfde628 2026-11-09 Add 7 points for a touchdown and the extra point 5ec675e 2026-11-06 Add 3 points for a field goal d3ecae5 2026-11-05 Add Score.java: print a starting score of 0
- dfde628, because Git lists the newest commit first
- d3ecae5, because the last line of a list is the newest
- 5ec675e, because the middle commit changed the most
- None of them, because a history does not record dates
MC 4. A builder changes a program so that it prints the score after each quarter instead of only at the end of the game. Which commit message is most useful in the history?
- update
- Changed some things in the program today
- Print the score after each quarter so fans can follow the game
- I opened the file this morning, worked on it for a while and then I was done
MC 5. Which columns does a trace table for this code need?
1int w = 6; 2int h = 2; 3int area = w * h; 4System.out.println(area);
- Line, w, h and Output
- Line, area and Output
- Line, w, h, area and Output
- Line, w, h, area, System and Output
MC 6. What is stored in k after all three lines run?
1int k = 9; 2k = k - 4; 3k = k * 3;
- 27
- 9
- 5
- 15
MC 7. A student traced this code. Row 1: m is 2. Row 2: m is 2 and n is 7. Row 3: m is 6 and n is 7. Row 4: m is 6 and n is 9. Which row is wrong?
1int m = 2; 2int n = m + 5; 3m = n - 1; 4n = m + n;
- Row 2
- Row 3
- Row 4
- No row is wrong
MC 8. What does this code print?
1int c = 4; 2int d = c * 2; 3c = 1; 4System.out.println(d);
- 8
- 2
- 1
- 4
MC 9. In Reading 2's worked table, the cell for b in row 1 is empty. Why?
- b holds 0 until a value is stored in it
- b does not exist yet, because line 2 is where b is declared
- b holds the same value as a, so the cell is left blank
- The table leaves b out because b is never printed
MC 10. In Java, what does the line x = x + 1; do?
- It claims that x is equal to x + 1, which can never be true.
- It keeps the old value of x and adds a second value beside it.
- It works out x + 1 and stores the result in x, replacing the old value.
- It prints the value of x + 1 on a new line.
CR 1. Fill a five-row trace table for this code, with the columns Line, p, q and Output, one row for each line. Then give what the code prints.
1int p = 5; 2int q = p - 2; 3p = p + q; 4q = q * p; 5System.out.println(q);
Write your answer in your lab notebook, labeled CR 1.
CR 2. In two sentences, explain why line 4 of Reading 2's worked example uses 10 for a and not 3.
Write your answer in your lab notebook, labeled CR 2.
The classwork form is not linked yet. Use Station View and write your answers in your lab notebook with the item labels.
CR 3. Name the columns this code needs, fill a trace table with one row for each of its six lines, and give the line where one value was replaced by another.
1int x = 2; 2int y = x + 4; 3int z = y - x; 4x = z * 2; 5System.out.println(x); 6System.out.println(y + z);
Write your answer in your lab notebook, labeled CR 3.
CR 4. A Java program prints how many students have arrived in a classroom. Write a useful commit message for each of these two changes. Change 1: the count used to start at 1, and the builder changes it to start at 0, because no one has arrived when the program starts. Change 2: the builder adds a line that prints the count again after one more student arrives.
Write your answer in your lab notebook, labeled CR 4.
Trace It
Open the bench, do its six jobs, then paste your credit code into the credit-code form. You can turn in up to three codes per bench; your best score is your grade.
Bench Basics opens during your class period.
The classwork form is not linked yet. Use Station View and write your answers in your lab notebook with the item labels.
This opens during your class period.