Introduction to Java · Introduction to Java Programming

Displaying Output with System.out.print()

Watch lectures

Displaying Output with System.out.print()

1. The Trio (beginner)

System (class) → out (print stream) → print/println/printf (methods). Beginners: print (same line), println (new line), printf (formatted).

2. Code — See the Difference

System.out.print("A");      // A (cursor stays!)
System.out.print("B");      // AB (same line!)
System.out.println("C");    // ABC + newline
System.out.println("D");    // D (next line)
System.out.println();       // blank line (spacing trick!)
System.out.println(10 + 20); // 30 (math first!)
System.out.println("sum=" + 10 + 20); // sum=1020 (join left-to-right trap!)
System.out.println("sum=" + (10 + 20)); // sum=30 (brackets fix!)
System.err.println("error!"); // red error stream (like out, but for errors)

3. How + Joins (critical!)

"a"+1+2 → "a12" (String first → all join). 1+2+"a" → "3a" (math first, then join). Rule: left-to-right; once String appears, rest joins.

4. Traps

  • print without newline in loops → one long line (add " " spaces!).
  • println(array) prints address [I@1a2b3c (not elements!) — use Arrays.toString(arr).
  • System capital S, out small — case matters!

5. Exam Points

  • print vs println trace — 3-5 marks, very frequent.
  • "sum="+10+20 vs "sum="+(10+20) — 3 marks, favourite trap.
Budget AppAndroid App

Pocketly on Android

Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.

← All Introduction to Java Programming modules