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
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 lineThe 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: 17What is the escape character \t used for?
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!"To output a quotation mark inside a text, you write \" instead of just ".
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\JavaTo 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 →