In the Hello World lesson, we learned how to use the println method of the System.out stream to output text to the computer’s display. There are several ways to make our printed output more readable.


Section 1 - Creating Longer String Literals


A single string literal cannot span multiple lines.

"Java is my                                // ERROR
    "favorite programming language"        // ERROR


If a string literal will not fit on a single line, split it up into several string literals separated by plus

(+) signs. Since the Java compiler uses the semicolon to mark the end of a statement, it can process statements that span multiple lines.

The following program prints the string “Java is my favorite programming language” on a single line.


Listing 1 -

public class UsingNewlines
    public static void main(String[] args)
       System.out.println("Java is my" +
                                 "favorite programming language");


Java is my favorite programming language



Copyright ©2017 by Ralph Lecessi Incorporated. All rights reserved.