Java Output / Print

</>Coding Tamilan.← Java course & curriculum
Java Masterclass · Lesson 04 / 50 · English

Java Output / Print

Give your program a voice.

Step-by-step explanationsRunnable JavaPractice + answer

Read this topic in தமிழ் ↗.

By the end of this lesson, you can…

  • Explain the key idea behind Output / Print.
  • Read and run a complete example, then predict what changes.
  • Recognize the topic-specific mistake discussed below.
01 / The concept

Understand the idea

Output is how a small console program tells you what it is doing. print writes without adding a line break; println writes and then finishes the line. When debugging, print meaningful labels so you can connect an output value to the variable that produced it.

02 / Step by step

Explore the details

Print Text

You learned from the previous chapter that you can use the println() method to output values or print text in Java:

You can add as many println() methods as you want. Note that it will add a new line for each method:

Double Quotes

Text must be wrapped inside double quotations marks "".

If you forget the double quotes, an error occurs:

The Print() Method

There is also a print() method, which is similar to println().

The only difference is that it does not insert a new line at the end of the output:

Note that we add an extra space (after "Hello World!" in the example above) for better readability.

In this tutorial, we will only use println() as it makes the code output easier to read.

print vs println vs printf

MethodAdds newline?Best for
System.out.print()NoOutput on the same line
System.out.println()YesOne value per line (most common)
System.out.printf()No (use %n)Formatted output with placeholders
Java reference fragmentJAVA
System.out.print("Hello ");       // no newline
System.out.println("World!");     // adds newline → Hello World!
System.out.printf("Hi %s! You are %d years old.%n", "Alice", 25);
// Hi Alice! You are 25 years old.

int x = 42;
System.out.println("Value: " + x);    // Value: 42  (concatenation)
System.out.printf("Value: %d%n", x);  // Value: 42  (formatted)
03 / Read and predict

A complete runnable example

This complete Main.java program focuses on the lesson idea. Reference fragments above may demonstrate individual statements; this example includes the imports, entry point, and supporting types it needs.

Main.java · complete runnable exampleJAVA
public class Main {
    public static void main(String[] args) throws Exception {
        System.out.print("Hello ");
        System.out.println("Tamilan!");
        System.out.printf("Completed: %d lessons%n", 4);
    }
}
Predict first. Then reveal the expected output / வெளியீடு
Hello Tamilan!
Completed: 4 lessons

The output shown was checked by running this complete example. Trace the executed statements in order, then compare with your run.

04 / Learn by changing

Change it. Run it. Understand it.

Load this lesson example into the editor. Change one value or statement, predict the result, then press RUN to execute Java.

Open Java editor ↗
After the editor loads, choose Load this lesson example, then press RUN.

Powered by OneCompiler. Code you run is sent to OneCompiler for execution. For Scanner examples, supply input in the editor I/O panel; for file examples, files exist in its execution environment.

05 / Your turn

Make it your own

Practice challenge

Change the first two calls to println and predict how many output lines there will be.

Reveal the answer and reasoning / விடை

The greeting now occupies two lines: Hello on one line and Tamilan! on the next. The completed count remains a separate third line.

One mistake to avoid: print and println are case-sensitive names. println contains a lowercase letter l, not the number 1.

Your learning checkpoint

  • Explain the example without reading the output first.
  • Make the change requested in the practice task.
  • Describe why the result changed—or why compilation failed.

Ready to move on? Follow the next lesson in course order, or return to the curriculum to review a prerequisite.

Coding Tamilan · Understand the idea. Try the code. Build the habit.