Question: A few days ago, i was asked about this program's output:

```
public static void main(String[] args) {
    // \u0022 is the Unicode escape for double quote (")
    System.out.println("a\u0022.length() + \u0022b".length());
}

```

My first thought was this program should print the `a\u0022.length() + \u0022b` length, which is `16` but surprisingly, it printed `2`. I know `\u0022` is the unicode for `"` but i thought this `"` going to be escaped and only represent one `"` literal, with no special meaning. And in reality, Java somehow parsed this string as following:

```
System.out.println("a".length() + "b".length());

```

I can't wrap my head around this weird behavior, Why Unicode escapes don't behave as normal escape sequences?

**Update** Apparently, this was one of brain teasers of the [Java Puzzlers: Traps, Pitfalls, and Corner Cases](https://rads.stackoverflow.com/amzn/click/com/032133678X) book written by Joshua Bloch and Neal Gafter. More specifically, the question was related to *Puzzle 14: Escape Rout*.

Answer: 
Before the compiler actually translates the source to bytecode, the lexical translation phase will turn the statement:

```
System.out.println("a\u0022.length() + \u0022b".length());

```

into:

```
System.out.println("a".length() + "b".length());

```

Hence the result is 2.

Also see [this section about lexical translation](https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.2) from the Language Specification:

> 
> A raw Unicode character stream is translated into a sequence of tokens, using the following three lexical translation steps, which are applied in turn:
> 
> 
> 1. A translation of Unicode escapes (§3.3) in the raw stream of Unicode characters to the corresponding Unicode character. A Unicode escape of the form \uxxxx, where xxxx is a hexadecimal value, represents the UTF-16 code unit whose encoding is xxxx. This translation step allows any program to be expressed using only ASCII characters.
> 
> 
>
It is just funny that the following works (taken from the reference)

```
System.out.println("a\".length() + \"b".length());

```

but the following produces a compile error

```
System.out.println("a\\\u0022.length() + \\\u0022b".length());

```

On the second one, the compiler should reduce the `\` and the `"`, put them together as `\"`, but it tried it and it doesn't compile (the `"` still closes the string).