CS I · Fri Dec 11 · 18.5 · Do Now

Java So Far

Open the discussion form on the right and answer Section 1 from your first reading.

Announcements

One Whole Java Program

This section traces one complete Java program from start to stop, using almost every skill from the Java benches since November. The program is shown with the line numbers that the bench's code panel would display.

1public class Main
2{
3    public static int doubleIt(int n)
4    {
5        return n * 2;
6    }
7
8    public static void main(String[] args)
9    {
10        int cups = 3;
11        cups = doubleIt(cups) + 1;
12        System.out.println("Cups: " + cups);
13        if (cups % 2 == 0)
14        {
15            System.out.println("even");
16        }
17        else
18        {
19            System.out.println("odd");
20        }
21    }
22}
Cups: 7
odd

Where the Program Starts and What It Stores

The program is one class named Main, and its braces come in pairs that open and close each part. Inside the class are two methods, doubleIt on lines 3 to 6 and main on lines 8 to 21. The Java Virtual Machine starts every program by running the method named main, so this program starts at line 8 even though doubleIt is written above it. The first statement to run is line 10, which stores 3 in the variable cups. In Java, the = sign means store, so the value on the right is placed in the variable on the left. Line 11 uses = again to replace the 3 in cups.

A Method's Input and Output

Line 11 calls doubleIt and passes it the argument cups. A method's input is the value that goes into the method when it is called, so the input to doubleIt is 3, and the parameter n holds 3 while the method runs. The 7 that the program prints later is not the input to doubleIt, because the input is the argument passed in, which is 3. Next, line 5 multiplies n by 2 and returns 6, and since a method's output is the value that it sends back, the output of doubleIt is 6. Returning a value is not the same as printing it, because the output of doubleIt goes back to line 11, where the call was, and nothing appears on the screen at that moment. Back in main, Java adds 1 to the returned 6 and stores 7 in cups. Figure 1 shows this path as a curved arrow from line 11 into doubleIt and back down.

Printing and Deciding

Line 12 joins the text "Cups: " with the number stored in cups, and it prints Cups: 7. This printed line is the program's first line of output, and because println ends its line, the next printed text starts on a new line.

Line 13 is an if statement, and it decides which of two blocks runs. A condition is a test whose value is either true or false. The condition on line 13 asks whether the remainder of cups divided by 2 is equal to 0. Java works it out in the steps below.

the condition on line 13, one step at a time
cups % 2 == 0
7 % 2 == 0
1 == 0
false

The remainder on the left side of the comparison is not a condition by itself, because it is the number 1, not true or false. The whole comparison is the condition, because its value is false. Since the condition is false, Java skips the if block on lines 14 to 16 and runs the else block, so line 19 prints odd, and the program stops at the closing brace of main on line 21.

The Whole Trace and a Check with Code Coach

The trace table below follows the program in the order that its lines run.

Line   n    cups   Output
10          3
11          3
5      3    3
11          7
12          7      Cups: 7
13          7
19          7      odd

The variable n has a value only on the row for line 5, because n belongs to doubleIt and exists only while that method runs. Line 11 appears twice, because the call sends control into doubleIt and the returned value comes back to the same line before it is stored.

On the bench, the Ask Code Coach panel opens only after a student checks a prediction, such as the value of cups after line 11. On October 20, 2026, Code Coach was sent this whole program with its line numbers and asked what line 11 does, in the same form the bench uses. The request was run twice, and the first explanation is below, word for word.

Line 11 calls the `doubleIt` method with `cups` (which is 3) as the argument. The method returns 6 (3 * 2), then adds 1, making it 7. It then stores this value back into the `cups` variable. So, `cups` now stores 7.

The second explanation, word for word, follows.

Line 11 calls the `doubleIt` method with the value of `cups` (which is 3), doubles it to 6, adds 1 to make 7, and stores the result back in `cups`. It then prints: `Cups: 7`.

The first explanation matches the trace table. It names the 3 that goes in, the 6 that comes back and the 7 that is stored, so it meets requirement R2, which says that every explanation names what the code prints or stores. The second explanation also names the stored 7, but its last sentence goes past line 11, because the trace table shows that line 12 prints Cups: 7. That sentence breaks requirement R1, which says that Code Coach explains only the Java the student asked about. One run stayed on line 11 and one went past it. A model generates every explanation, so the student checks each one against the trace table and the real output before trusting it.

Summary

A Java program starts at main, stores values with =, and runs its lines in order unless a method call or an if statement changes that order. A method's input is the argument passed in, its output is the value it returns, and a returned value reaches the screen only when a println prints it. A condition is true or false, and it decides which block runs.

Sources: College Board, AP Computer Science A Course and Exam Description (2025); Oracle, The Java Language Specification, Java SE 21 Edition, §12.1 (2023); Code Coach captured explanations, cups-full-line11 (2026); Code Coach requirements and bench code, course repository (2026); CS I Reading 2 texts, Nov 2, Nov 3, Nov 18 and Dec 2 (2026); the program run with the course JDK (2026).

I Do questions
  1. notebook cue: input

    When `main` calls `doubleIt(cups)`, what value goes into the method as its input?

    Check

    The input is 3. Line 11 passes the argument cups, which holds 3 at that moment, so the parameter n holds 3 while doubleIt runs. The 7 printed later is not the input. See A Method's Input and Output, and the "input: 3" tag in Figure 1.

  2. notebook cue: output

    `doubleIt` returns 6. Does 6 ever appear on the screen? Why or why not?

    Check

    No. The 6 is doubleIt's output, and it goes back to line 11, where Java adds 1 and stores 7 in cups. Returning a value is not printing it, so the only lines on the screen are Cups: 7 and odd. See A Method's Input and Output, and the trace table in The Whole Trace and a Check with Code Coach.

  3. notebook cue: condition

    What is the condition in the `if` statement, and why does the program print `odd`?

    Check

    The condition is the test on line 13, which asks whether the remainder of cups divided by 2 is equal to 0. With cups at 7 the remainder is 1, so the condition is false, the else block runs, and line 19 prints odd. See Printing and Deciding, paragraph 2, and the condition callout in Figure 1.

Figure 1. The passage's program with the line numbers the bench shows, the call from line 11 into doubleIt and back, the condition on line 13 worked out, and the full trace table.
I Do questions
  1. notebook cue: input

    When `main` calls `doubleIt(cups)`, what value goes into the method as its input?

    Check

    The input is 3. Line 11 passes the argument cups, which holds 3 at that moment, so the parameter n holds 3 while doubleIt runs. The 7 printed later is not the input. See A Method's Input and Output, and the "input: 3" tag in Figure 1.

  2. notebook cue: output

    `doubleIt` returns 6. Does 6 ever appear on the screen? Why or why not?

    Check

    No. The 6 is doubleIt's output, and it goes back to line 11, where Java adds 1 and stores 7 in cups. Returning a value is not printing it, so the only lines on the screen are Cups: 7 and odd. See A Method's Input and Output, and the trace table in The Whole Trace and a Check with Code Coach.

  3. notebook cue: condition

    What is the condition in the `if` statement, and why does the program print `odd`?

    Check

    The condition is the test on line 13, which asks whether the remainder of cups divided by 2 is equal to 0. With cups at 7 the remainder is 1, so the condition is false, the else block runs, and line 19 prints odd. See Printing and Deciding, paragraph 2, and the condition callout in Figure 1.

One Whole Java Program

This section traces one complete Java program from start to stop, using almost every skill from the Java benches since November. The program is shown with the line numbers that the bench's code panel would display.

1public class Main
2{
3    public static int doubleIt(int n)
4    {
5        return n * 2;
6    }
7
8    public static void main(String[] args)
9    {
10        int cups = 3;
11        cups = doubleIt(cups) + 1;
12        System.out.println("Cups: " + cups);
13        if (cups % 2 == 0)
14        {
15            System.out.println("even");
16        }
17        else
18        {
19            System.out.println("odd");
20        }
21    }
22}
Cups: 7
odd

Where the Program Starts and What It Stores

The program is one class named Main, and its braces come in pairs that open and close each part. Inside the class are two methods, doubleIt on lines 3 to 6 and main on lines 8 to 21. The Java Virtual Machine starts every program by running the method named main, so this program starts at line 8 even though doubleIt is written above it. The first statement to run is line 10, which stores 3 in the variable cups. In Java, the = sign means store, so the value on the right is placed in the variable on the left. Line 11 uses = again to replace the 3 in cups.

A Method's Input and Output

Line 11 calls doubleIt and passes it the argument cups. A method's input is the value that goes into the method when it is called, so the input to doubleIt is 3, and the parameter n holds 3 while the method runs. The 7 that the program prints later is not the input to doubleIt, because the input is the argument passed in, which is 3. Next, line 5 multiplies n by 2 and returns 6, and since a method's output is the value that it sends back, the output of doubleIt is 6. Returning a value is not the same as printing it, because the output of doubleIt goes back to line 11, where the call was, and nothing appears on the screen at that moment. Back in main, Java adds 1 to the returned 6 and stores 7 in cups. Figure 1 shows this path as a curved arrow from line 11 into doubleIt and back down.

Printing and Deciding

Line 12 joins the text "Cups: " with the number stored in cups, and it prints Cups: 7. This printed line is the program's first line of output, and because println ends its line, the next printed text starts on a new line.

Line 13 is an if statement, and it decides which of two blocks runs. A condition is a test whose value is either true or false. The condition on line 13 asks whether the remainder of cups divided by 2 is equal to 0. Java works it out in the steps below.

the condition on line 13, one step at a time
cups % 2 == 0
7 % 2 == 0
1 == 0
false

The remainder on the left side of the comparison is not a condition by itself, because it is the number 1, not true or false. The whole comparison is the condition, because its value is false. Since the condition is false, Java skips the if block on lines 14 to 16 and runs the else block, so line 19 prints odd, and the program stops at the closing brace of main on line 21.

The Whole Trace and a Check with Code Coach

The trace table below follows the program in the order that its lines run.

Line   n    cups   Output
10          3
11          3
5      3    3
11          7
12          7      Cups: 7
13          7
19          7      odd

The variable n has a value only on the row for line 5, because n belongs to doubleIt and exists only while that method runs. Line 11 appears twice, because the call sends control into doubleIt and the returned value comes back to the same line before it is stored.

On the bench, the Ask Code Coach panel opens only after a student checks a prediction, such as the value of cups after line 11. On October 20, 2026, Code Coach was sent this whole program with its line numbers and asked what line 11 does, in the same form the bench uses. The request was run twice, and the first explanation is below, word for word.

Line 11 calls the `doubleIt` method with `cups` (which is 3) as the argument. The method returns 6 (3 * 2), then adds 1, making it 7. It then stores this value back into the `cups` variable. So, `cups` now stores 7.

The second explanation, word for word, follows.

Line 11 calls the `doubleIt` method with the value of `cups` (which is 3), doubles it to 6, adds 1 to make 7, and stores the result back in `cups`. It then prints: `Cups: 7`.

The first explanation matches the trace table. It names the 3 that goes in, the 6 that comes back and the 7 that is stored, so it meets requirement R2, which says that every explanation names what the code prints or stores. The second explanation also names the stored 7, but its last sentence goes past line 11, because the trace table shows that line 12 prints Cups: 7. That sentence breaks requirement R1, which says that Code Coach explains only the Java the student asked about. One run stayed on line 11 and one went past it. A model generates every explanation, so the student checks each one against the trace table and the real output before trusting it.

Summary

A Java program starts at main, stores values with =, and runs its lines in order unless a method call or an if statement changes that order. A method's input is the argument passed in, its output is the value it returns, and a returned value reaches the screen only when a println prints it. A condition is true or false, and it decides which block runs.

Sources: College Board, AP Computer Science A Course and Exam Description (2025); Oracle, The Java Language Specification, Java SE 21 Edition, §12.1 (2023); Code Coach captured explanations, cups-full-line11 (2026); Code Coach requirements and bench code, course repository (2026); CS I Reading 2 texts, Nov 2, Nov 3, Nov 18 and Dec 2 (2026); the program run with the course JDK (2026).

Table Talk
Think back to the first Java bench you did in November. Name one thing you can do with Java now that you could not do then, and one thing that still trips you up.

Each table agrees on the Java skill most of its members trust, and on the one they most want to practise before the final.

Chromebooks stay closed while your table talks. Sections 1 and 2 of the discussion form are already done. After you talk, finish Section 3 right here under My View. Submit before the exit ticket.

This form has three sections. Section 1: answer today's Board Question. Section 2: after the reading. Section 3 opens later in class. Today's Board Question: Think back to the first Java bench you did in November. Name one thing you can do with Java now that you could not do then, and one thing that still trips you up.

CR 1. Board Question: Think back to the first Java bench you did in November. Name one thing you can do with Java now that you could not do then, and one thing that still trips you up. Give your answer and one reason.

Write your answer in your lab notebook, labeled CR 1.

MC 1. Think about your answer to the board question. Think back to the first Java bench you did in November. Name one thing you can do with Java now that you could not do then, and one thing that still trips you up. Which position is closest to yours now?

  • Printing. I can say what a `println` line shows, line breaks and all.
  • Tracing. I can follow a program line by line in a table, even into a method and back.
  • Decisions. I can tell which branch of an `if` and `else` runs for a value.

MC 2. (Reading claim 1) A Java program always starts at the first line of the file.

  • Agree
  • Disagree

MC 3. (Reading claim 2) A method's returned value appears on the screen as soon as it returns.

  • Agree
  • Disagree

MC 4. (Reading claim 3) A condition in Java is always either true or false.

  • Agree
  • Disagree

MC 5. (Reading claim 4) In the passage's program, the input to doubleIt is 3, the value stored in cups when line 11 calls it.

  • Agree
  • Disagree

MC 6. (Reading claim 5) Line 11 of the passage's program prints 6 on the screen before line 12 runs.

  • Agree
  • Disagree

MC 7. (Reading claim 6) In Figure 1, the condition on line 13 is false, so the else block runs and prints odd.

  • Agree
  • Disagree

MC 8. (Reading claim 7) Both of Code Coach's saved explanations of line 11 explain only what line 11 does.

  • Agree
  • Disagree

MC 9. (Reading claim 8) In the trace table, the variable n has a value only on the row for line 5.

  • Agree
  • Disagree

CR 2. (A different view) Write the view at your table that was most different from yours. If everyone agreed, write the strongest argument against your table's answer.

Write your answer in your lab notebook, labeled CR 2.

CR 3. Think about the Board Question again: Think back to the first Java bench you did in November. Name one thing you can do with Java now that you could not do then, and one thing that still trips you up. Do you have the same opinion as when you first answered the board question? If it is the same, what from the reading or table talk reaffirmed your opinion? If it is different, what from the reading or table talk changed your opinion?

Write your answer in your lab notebook, labeled CR 3.