Displaying Strings in Programs

The most basic way to display a string in a Java program is with the System.out.println() statement. This statement takes any strings and other variables inside the parentheses and displays their values. The following statement displays a line of text to the system output device, which is the computer's monitor:

System.out.println("Silence affects everyone in the end.");

The preceding statement would cause the following text to be displayed:

Silence affects everyone in the end.

Displaying a line of text on the screen is often called printing, which is what println() stands for—”print this line.” You can use the System.out.println() statement to display text within double quotation marks and also to display variables, ...

Get SAMS Teach Yourself Programming with Java™ in 24 Hours, FOURTH EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.