Introduction
Standard output is what we use to print out to a console window from within a Java program. Since Java is an object oriented language, almost everything exists inside a class. Accessing the standard output is no different. However, using the standard output does not required a complete understanding of the underlying class structure.
Please note: To use the standard output you should first explore the Java code organization. To understand class structures in Java, you can begin with Using Existing Classes.
Syntax
General syntax for printing to standard output and ending with a new line:
System.out.println(…);
General syntax for printing to standard output and remaining on the same line:
System.out.print(…);
Standard Java spacing:
There should never be a space between print or println and the opening parenthesis, because these are method calls that should be firmly attached to the argument list inside the parentheses. Also, it is standard Java convention not to add any space on either side of any parenthesis unless required by the adjacent item.
Basic usage:
System.out.println(“Hello, World!”);
System.out.print(1999);
Practice
Your turn! Open your Java IDE of choice. (We recommend InteliJ IDEA .)
Project 1:
Create a Java program that outputs some information about yourself to the console. Try using both print and println statements. Try outputting some values without quotation marks around them, incorporating them into your narrative.
Example outcome:
Hi, my name is Fred Flintstone!
I live in the great city of Bedrock with my wife, Wilma.
I’ve been working at Slate Rock and Gravel Company since 1960!
Project 2:
Create some console art of your own. Experiment with print and println statements and with escape sequences like \”, \n, and \\.
Example outcome:
*********
*****
/\ ***
/ \ |*|
/ \| |
/ | |
/ /\ \|
/ /__\ \
| | | | __________________
_______|___|__|___|_______
____
Assessment:
Sign in to submit your projects for evaluation, take the online completion quiz, notify an instructor of your accomplishment, or apply your work to stream certificates.