Java Escape / Unescape
This Java escaper prepares text for a Java string literal. It accounts for the ways Java differs from other C-family languages: there is no \v escape and no \0 escape, so a vertical tab and a null byte are written as \u000B and \u0000 rather than the shorter forms other languages accept — the result compiles rather than merely looking right. An ASCII-only option converts every character above ASCII to a \uXXXX escape, with characters outside the basic plane written as a surrogate pair, which is what .properties and resource bundle files traditionally require.
How it works
Escapes a value for a Java string literal. Java has no \v or \0 escape, so a vertical tab and a null byte are written as \u000B and \u0000 rather than the shorter forms other languages accept.
Turn on the ASCII-only option for .properties files and other sources that must stay 7-bit: every character above ASCII becomes a \uXXXX escape, with astral characters written as a surrogate pair.
Escaping runs entirely in your browser — nothing you paste is sent to a server.
0 characters in · 0 characters out
How to escape a Java string
- Paste your text into the input on the left.
- Turn on the ASCII-only option if the file must stay 7-bit.
- Copy the escaped body into your Java string literal.
Where Java differs from JavaScript
Java has no \v escape and no \0 escape, so a vertical tab and a null byte have to be
written as \u000B and \u0000. Escaping here uses the numeric forms for exactly those
two, so the result compiles rather than looking right and failing.
ASCII-only output for .properties files
Java properties files are read as ISO-8859-1 unless you go out of your way, which is why accented characters and
anything non-Latin traditionally appear as \uXXXX escapes. Turn the option on and every character
above ASCII is converted, with characters outside the basic plane written as a surrogate pair.
Common use cases
- Putting a JSON fixture or SQL statement into a string constant in a test.
- Preparing values for a
.propertiesor resource bundle file. - Decoding escaped text pulled out of a log or a compiled class.
Frequently asked questions
How does Java escaping differ from JavaScript?
Java has no \v and no \0 escape, so a vertical tab and a null byte must be written as \u000B and \u0000. Using the shorter forms produces code that will not compile.
When should I use the ASCII-only option?
For .properties files and resource bundles, which are read as ISO-8859-1 unless configured otherwise — which is why non-Latin text traditionally appears there as \uXXXX escapes.
How are emoji and other astral characters handled?
They are written as a surrogate pair of \uXXXX escapes, because Java strings are sequences of UTF-16 code units and a single escape cannot express a code point above U+FFFF.
Does the output include the surrounding quotes?
No. You get the body of the literal, ready to paste between quote marks already present in your source.
Is my text uploaded?
No. Everything is escaped locally in your browser.
Related tools
JavaScript Escape / Unescape
This JavaScript escaper prepares any text to sit inside a string literal without breaking it.
C# / .NET Escape / Unescape
This C# escaper prepares text for a regular string literal, with a note on verbatim strings.
Base64 Encoder / Decoder
Encode text to Base64 or decode Base64 back to plain text, entirely in your browser, with full UTF-8 support.