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 strings and other variables inside the parentheses and displays their values on the system output device, which is the computer’s monitor. Here’s an example:

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

This statement causes the following text to be displayed:

Silence affects everyone in the end.

Displaying text on the screen often is called printing, which is what println() stands for—print line. You can use the System.out.println() statement to display text within double quotation marks and also to display variables, as you see later. Put all the material you want to be displayed ...

Get Sams Teach Yourself Java™ in 24 Hours, Sixth 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.