ToolLineup

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.

Plain text input
Paste the text to escape…
Escaped Java string

0 characters in · 0 characters out

How to escape a Java string

  1. Paste your text into the input on the left.
  2. Turn on the ASCII-only option if the file must stay 7-bit.
  3. 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 .properties or 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