….
🖨️ Java Output – Printing Text to the Console
One of the first things you’ll do in any programming language is display output — and in Java, it’s simple and powerful. At GoNimbus, we make sure you not only know how to print text but also why it behaves the way it does.
🟢 Printing with System.out.println()
The most commonly used method for printing output in Java is:
System.out.println("Hello, GoNimbus Learner!");
System
is a built-in Java class.out
is a static member of theSystem
class, representing the standard output stream.println()
is a method that prints text followed by a new line.
Every time you use println()
, it moves the cursor to the next line after printing.
✅ Example:
System.out.println("Java is fun!");
System.out.println("GoNimbus makes learning easy!");
System.out.println("Let's master Java together!");
🖥️ Output:
Java is fun!
GoNimbus makes learning easy!
Let's master Java together!
📝 Using Double Quotes
All text (also called string literals) must be enclosed in double quotes " "
.
🚫 Incorrect:
System.out.println(This will cause an error); // Missing quotes
✅ Correct:
System.out.println("This will print successfully.");
🔄 The System.out.print()
Method
Java also gives you another option: the print()
method.
The only difference?
🟡 print()
does not move to a new line after outputting the text.
📌 Example:
System.out.print("GoNimbus ");
System.out.print("Java ");
System.out.print("Course");
🖥️ Output:
GoNimbus Java Course
You’ll often use
print()
when you want to display text continuously on the same line.
💡 Why Add a Space Manually?
When using print()
, Java won’t insert any space between printed texts — you have to do it yourself:
System.out.print("Hello");
System.out.print("World");
🖥️ Output:
HelloWorld
✅ Fix it by adding a space:
System.out.print("Hello ");
System.out.print("World");
🖥️ Output:
Hello World
🆚 print()
vs println()
– Quick Comparison
Feature | System.out.print() | System.out.println() |
---|---|---|
Ends with a newline? | ❌ No | ✅ Yes |
Output continues on the same line? | ✅ Yes | ❌ No |
Useful for? | Inline output | Separate line output |
💬 GoNimbus Tip
Stick with
println()
while learning. It keeps your output clean and avoids confusion with line breaks.
🧪 Practice Now!
Open the GoNimbus Java Playground and try this:
public class OutputExample {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
System.out.print("Learning ");
System.out.print("with ");
System.out.print("GoNimbus.");
}
}
🖥️ Output:
Welcome to Java!
Learning with GoNimbus.
🔜 Coming Up Next: Java Variables & Data Types
Now that you know how to show output, let’s learn how to store data in your Java programs using variables!