Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Output · Lesson 18 of 28

Escape Characters

A free lesson from Swipe Coding · Java, level 2 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
Some characters need a little help to show up in your text. 🔡

Sometimes you want to output things in a text that cannot simply be written as-is — for example a line break in the middle of a sentence, or a quotation mark. For this, there are "escape characters": a backslash (\) followed by a letter that has a special meaning.

System.out.println("First line\nSecond line");

// Output:
// First line
// Second line
\n produces a line break — in the middle of a single println() call.
Fill in the blank

The escape character ____ produces a line break in the middle of the text.

The escape character \t produces a tab — a larger, even amount of spacing. This lets you roughly align text into columns.

System.out.println("Name:\tMax");
System.out.println("Age:\t17");

// Output:
// Name:   Max
// Age:    17
\t makes sure that "Max" and "17" line up roughly underneath each other, even though "Name:" and "Age:" have different lengths.
Quick check

What is the escape character \t used for?

🤖
This trick lets a quotation mark exist peacefully inside a string. 💬

If you want to output a regular quotation mark in the middle of a text, there is a problem: Java would think the string ends there. The solution is \" — an "escaped" quotation mark that is treated as plain text.

System.out.println("She said: \"Java is awesome!\"");

// Output:
// She said: "Java is awesome!"
Without the backslash before the quotation marks, Java would end the string too early and report an error.
True or false

To output a quotation mark inside a text, you write \" instead of just ".

🤖
Even backslashes need their own special trick to print. ⚙️

And what if you want to output a backslash itself — for example in a file path? Since a single backslash normally starts an escape character, you have to double it: \\.

System.out.println("The path is: C:\\Programs\\Java");

// Output:
// The path is: C:\Programs\Java
Each \\ in the code produces exactly one single backslash in the output.
Fill in the blank

To output a single backslash, you write ____ in the code.

Keep your streak going in Swipe Coding

Swipe through every level of Java on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.

Get the Swipe apps →