dcsimg
 

Syntax for Unicode Escapes in Java

Monday Sep 16th 2019 by Octavia Anghel

Language: Java, Expertise: Intermediate - In addition to the string and character escape sequences, Java has a more general Unicode escaping mechanism. See how to use it.

In addition to the string and character escape sequences, Java has a more general Unicode escaping mechanism, as defined in JLS 3.3. Unicode Escapes. A Unicode escape has the following syntax:

'\' 'u' < hex-digit> < hex-digit> < hex-digit> < hex-digit>

Where <hex-digit> is one of '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F'.

A Unicode escape is mapped by the Java compiler to a character (strictly speaking a 16-bit Unicode code unit) and can be used anywhere in the source code where the mapped character is valid. It is commonly used in character and string literals when you need to represent a non-ASCII character in a literal.

Home
Mobile Site | Full Site