---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 15 Edition"
java_version: 15
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/se15/html/jls-3.html#jls-3.2
id: "3.2"
url: https://jvm.obfuscated.software/jls/se15/3.2.html
raw: https://jvm.obfuscated.software/jls/se15/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 ([§3.5](3.5.md)) 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 is one exception: if lexical translation occurs in a type context ([§4.11](4.11.md)) and the input stream has two or more consecutive `>` characters that are followed by a non-`>` character, then each `>` character must be translated to the token for the numerical comparison operator `>`.

The input characters `a--b` are tokenized ([§3.5](3.5.md)) as `a`, `--`, `b`, which is not part of any grammatically correct program, even though the tokenization `a`, `-`, `-`, `b` could be part of a grammatically correct program.

Without the rule for `>` characters, two consecutive `>` brackets in a type such as `List<List<String>>` would be tokenized as the signed right shift operator `>>`, while three consecutive `>` brackets in a type such as `List<List<List<String>>>` would be tokenized as the unsigned right shift operator `>>>`. Worse, the tokenization of four or more consecutive `>` brackets in a type such as `List<List<List<List<String>>>>` would be ambiguous, as various combinations of `>`, `>>`, and `>>>` tokens could represent the `>>>>` characters.
