---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 19 Edition"
java_version: 19
chapter: "Chapter 3. Lexical Structure"
section: "3.10.7"
heading: "3.10.7. Escape Sequences"
parent: "3.10. Literals"
source: https://docs.oracle.com/javase/specs/jls/se19/html/jls-3.html#jls-3.10.7
id: "3.10.7"
url: https://jvm.obfuscated.software/jls/se19/3.10.7.html
raw: https://jvm.obfuscated.software/jls/se19/3.10.7.md
---

# 3.10.7. Escape Sequences

In character literals, string literals, and text blocks ([§3.10.4](3.10.4.md), [§3.10.5](3.10.5.md), [§3.10.6](3.10.6.md)), the *escape sequences* allow for the representation of some nongraphic characters without using Unicode escapes ([§3.3](3.3.md)), as well as the single quote, double quote, and backslash characters.

```
EscapeSequence:
  \ b (backspace BS, Unicode \u0008)
  \ s (space SP, Unicode \u0020)
  \ t (horizontal tab HT, Unicode \u0009)
  \ n (linefeed LF, Unicode \u000a)
  \ f (form feed FF, Unicode \u000c)
  \ r (carriage return CR, Unicode \u000d)
  \ LineTerminator (line continuation, no Unicode representation)
  \ " (double quote ", Unicode \u0022)
  \ ' (single quote ', Unicode \u0027)
  \ \ (backslash \, Unicode \u005c)
  OctalEscape (octal value, Unicode \u0000 to \u00ff)

OctalEscape:
  \ OctalDigit
  \ OctalDigit OctalDigit
  \ ZeroToThree OctalDigit OctalDigit

OctalDigit:
  (one of)
  0 1 2 3 4 5 6 7

ZeroToThree:
  (one of)
  0 1 2 3
```

The *OctalDigit* production above comes from [§3.10.1](3.10.1.md). Octal escapes are provided for compatibility with C, but can express only Unicode values `\u0000` through `\u00FF`, so Unicode escapes are usually preferred.

It is a compile-time error if the character following a backslash in an escape sequence is not a *LineTerminator* or an ASCII `b`, `s`, `t`, `n`, `f`, `r`, `"`, `'`, `\`, `0`, `1`, `2`, `3`, `4`, `5`, `6`, or `7`.

An escape sequence in the content of a character literal, string literal, or text block is *interpreted* by replacing its `\` and trailing character(s) with the single character denoted by the Unicode escape in the *EscapeSequence* grammar. The line continuation escape sequence has no corresponding Unicode escape, so is interpreted by replacing it with nothing.

The line continuation escape sequence can appear in a text block, but cannot appear in a character literal or a string literal because each disallows a *LineTerminator*.
