The following rules apply to Unicode literals.
-
Unicode literals are treated as a sub-type of a character literal when used in expressions.
-
Unicode literals require single quotes. This is also a requirement for any character literal.
-
For Unicode literals, each Unicode character must begin with a single back slash followed by the small letter "u" and exactly 4 valid hexadecimal digits. The 4 digits taken together can represent any Unicode character from \u0000 to \uFFFF.
-
A Unicode literal must only contain Unicode escaped characters.
-
A Unicode literal cannot contain any of the other allowed escaped characters.
-
A character literal cannot contain a mixture of Unicode and non-Unicode characters.
Note: Precisely uses the standard Java convention to represent a Unicode character. This is because when you construct an escape sequence of characters in a Java string ("\uxxxx" where xxxx is some hexadecimal number), and the expression is generated, the compiler automatically generates the appropriate Unicode characters in the string.