Skip to main content
📜 WAYPOINT LESSON

Tracing execution

⭐ beginner⏳ 10 min read📍 Lesson 2 of 256

main runs top to bottom; print vs println; printing expressions vs text.

main runs top to bottom. Trace it like the exam asks you to:

public class Solution {
    public static void main(String[] args) {
        System.out.print("AB");
        System.out.println("CD");
        System.out.println("EF");
    }
}

Output:

ABCDEF
EF

Why two lines, not three? print("AB") writes AB and stays on the same line; println("CD") finishes that line. Trace rules:

  1. One statement at a time, in order.
  2. print stays on the line; println ends it.
  3. println() with no argument prints just a blank line.

You can also print computed values:

System.out.println(3 + 4);        // 7
System.out.println("3 + 4");      // 3 + 4

Quotes make text; no quotes means Java evaluates the expression first.

⚡ Now practice

Ready to Code
First programsWrite, predict, and fix complete Java programs.
4 challenges · · ~35 min