Syntax for Unicode Escapes in Java

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 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.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Related Posts