Week 14 · 14.4 · Fri, Nov 6 · The Specific Skills + Try Its
Java Symbols: Typing Java Exactly
Java is picky about every symbol you type. Today you learn what each symbol does, why capital letters matter, the difference between = and ==, the two jobs of +, and how to read an error message. Those are the five kinds of steps on today's bench.
Symbols and Their Jobs
Big idea. Java symbols are like punctuation in English, except that Java will not read past even one missing piece.
Every symbol in a line of Java has a job, and Java checks each one before the program runs. Here are the symbols the bench asks about.
symbol its job example
; ends a statement int count = 3;
{ } start and end a block of lines the body of main
( ) hold what a method is given println("Hi")
" " mark text that prints as written "Who dat?"
= stores a value in a box count = 3;
== asks whether two values are equal count == 3
How to read a line of Java:
- Find the semicolon that ends the statement.
- Find any text in quotation marks. It prints exactly as written.
- Read what is left from left to right.
Example 1. Name the jobs of the symbols in one statement.
1System.out.println("Hi");
Show the solution
The parentheses hold what println is given: the text to print. The quotation marks show where that text starts and ends, so Hi prints as written. The semicolon ends the statement.
Example 2. A pair of braces makes a block. The lines inside still run once each, in order.
1System.out.println("A"); 2{ 3 System.out.println("B"); 4} 5System.out.println("C");
Show the solution
A B C
Capital Letters Count
Big idea. To Java, System and system are as different as two passwords that differ by one capital letter.
Java is case-sensitive: to Java, a capital S and a small s are different letters. Java does not guess what you meant, so one wrong letter stops the program.
Example 3. Compare System.out.println("Hi"); with system.out.println("Hi"); which differ by one letter. Which one compiles?
Show the solution
System.out.println("Hi"); compiles: System starts with a capital S
system.out.println("Hi"); does not compile: system is a different name
A person can tell what the second line means, but Java cannot. It stops the whole program.
Store or Ask: = and ==
Big idea. = is a command: put this value in the box. == is a question: are these two equal?
One equals sign, =, stores: it puts the value on its right into the box on its left. Two equals signs, ==, ask a question: are these two values equal? The answer is true or false.
This is a switch from the steps language. There you stored with ← and asked with =. In Java you store with = and ask with ==.
Example 4. Store, then ask.
1int x = 4; 2System.out.println(x == 4); 3x = 5; 4System.out.println(x == 4);
Show the solution
true false
Line 1 stores 4 in x. Line 2 asks, is x equal to 4? It is, so it prints true. Line 3 stores 5 in x. Line 4 asks the same question, but now x is 5, so it prints false.
+ Adds or Joins
Big idea. + is a calculator until it meets text in quotes. From then on, it is glue.
The + sign has two jobs. Between two numbers, it adds them. If either side is text in quotes, it joins the two sides into one piece of text. Java works through + from left to right, and anything in parentheses comes first.
Example 5. Add numbers, then join text.
1System.out.println(2 + 3); 2System.out.println("2" + "3");
Show the solution
5 23
Example 6. Start with text.
1System.out.println("Total: " + 2 + 3);
Show the solution
Total: 23
Many readers write Total: 5. But going left to right, "Total: " + 2 joins into the text Total: 2. That is text now, so the 3 is joined on too: Total: 23.
Example 7. Start with numbers.
1System.out.println(2 + 3 + " points");
Show the solution
5 points
Going left to right, 2 + 3 comes first, and both sides are numbers, so it adds to 5. Then the text is joined on: 5 points.
Example 8. Use parentheses to add first.
1System.out.println("Sum: " + (2 + 3));
Show the solution
Sum: 5
Reading a Syntax Error
Big idea. An error message is a map: the line number is the street, and the caret, ^, is the house.
When a symbol is missing or wrong, Java reports a syntax error and nothing runs. The message tells you three things: the line number, the code on that line, and a caret, ^, pointing to where Java noticed the problem.
Example 9. A program's statement int b = 6 has no semicolon, and it is on line 4 of the file. The compiler reports Main.java:4: error: ';' expected and shows the line with a caret under it. Where does the semicolon belong?
Show the solution
Main.java:4: error: ';' expected
int b = 6
^
1 error
The message says a semicolon was expected on line 4, and the caret points just after the 6. That is where the semicolon belongs. Add it, and the whole program runs.
Finding a Bug
Big idea. Finding a bug is like checking a receipt: compare what you expected with what you got, line by line, and stop at the first difference.
A program can run and still print the wrong thing. That is a bug. These steps help you find the line that went wrong:
- Write down the expected output, line by line, before running the program.
- Run the program and write down what it printed.
- Compare the two, line by line, and find the first line that differs.
- Start at main and follow the statements in order to the one that printed that line.
- Check that statement and the ones that ran before it.
Example 10. The program should print Kickoff, then Halftime, then Final.
1public class Main 2{ 3 public static void main(String[] args) 4 { 5 System.out.print("Kickoff"); 6 System.out.println("Halftime"); 7 System.out.println("Final"); 8 } 9}
Show the solution
KickoffHalftime Final
line expected printed 1 Kickoff KickoffHalftime 2 Halftime Final 3 Final (nothing)
Compare the two lists. The very first output line is already different: KickoffHalftime instead of Kickoff. Code line 5 printed it, and it uses print, which leaves the line open, so Halftime landed on the same line. Changing line 5 to println fixes the bug.
Quick checks.
- What does System.out.println(1 + 1 + "1"); print? (21: 1 + 1 is worked first and makes 2, and then "1" is glued on.) - Which one stores and which one asks: x = 5; or x == 5? (x = 5; stores 5 in x. x == 5 asks whether x is 5.)
Watch for three common mistakes on the bench. First, capital letters count. Second, = stores and == asks. Third, + joins once one side is text. And when a program runs but prints the wrong thing, find the first output line that differs before you change anything.
Sources: Oracle, The Java Tutorials: Expressions, Statements, and Blocks, Equality, Relational, and Conditional Operators, Assignment, Arithmetic, and Unary Operators, Variables, Strings and Common Problems (and Their Solutions); course repository, Bench Basics B14 job data (2026), run with the course JDK.
Work each one in your notebook first, then check it.
Try It 1. In Java, what is the job of the semicolon in int count = 3; ?
Try It 2. In System.out.println("Hi"); which symbols mark the text that prints exactly as written?
Try It 3. Which line compiles?
Try It 4. Java is case-sensitive. What does that mean?
Try It 5. Which line asks whether score is equal to 10?
Try It 6. x holds 7. What does System.out.println(x == 8); print?
Try It 7. What does System.out.println(4 + 5); print?
Try It 8. What does System.out.println("4" + "5"); print?
Try It 9. What does System.out.println("Score: " + 1 + 2); print?
Try It 10. The compiler reports "error: ';' expected" with a caret just after int n = 2 . What fixes it?
Try It 11. A program has nine correct lines and one line with a syntax error. How many lines run?