---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 25 Edition"
java_version: 25
chapter: "Chapter 3. Lexical Structure"
section: "3.2"
heading: "3.2. Lexical Translations"
parent: "Chapter 3. Lexical Structure"
source: https://docs.oracle.com/javase/specs/jls/se25/html/jls-3.html#jls-3.2
id: "3.2"
url: https://jvm.obfuscated.software/jls/se25/3.2.html
raw: https://jvm.obfuscated.software/jls/se25/3.2.md
---

# 3.2. Lexical Translations

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](3.3.md)) 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.
2. A translation of the Unicode stream resulting from step 1 into a stream of input characters and line terminators ([§3.4](3.4.md)).
3. A translation of the stream of input characters and line terminators resulting from step 2 into a sequence of input elements ([§3.5](3.5.md)) which, after white space ([§3.6](3.6.md)) and comments ([§3.7](3.7.md)) are discarded, comprise the tokens that are the terminal symbols of the syntactic grammar ([§2.3](2.3.md)).

The longest possible translation is used at each step, even if the result does not ultimately make a correct program while another lexical translation would. There are two exceptions to account for situations that need more granular translation: in step 1, for the processing of contiguous `\` characters ([§3.3](3.3.md)), and in step 3, for the processing of contextual keywords and adjacent `>` characters ([§3.5](3.5.md)).

The input characters `a--b` are tokenized as `a`, `--`, and `b`, which is not part of any grammatically correct program, even though the tokenization `a`, `-`, `-`, `b` could be part of a grammatically correct program. The tokenization `a`, `-`, `-`, `b` can be realized with the input characters `a- -b` (with an ASCII SP character between the two `-` characters).

It might be supposed that the raw input `\\u1234` is translated to a `\` character and (following the "longest possible" rule) a Unicode escape of the form `\u1234`. In fact, the leading `\` character causes this raw input to be translated to seven distinct characters: `\ \ u 1 2 3 4`.
