OTHER USEFUL INFORMATION
What is Unicode?
Unicode is a shared standard for the world's writing systems. It assigns a unique number to each letter, symbol or emoji so different programs and devices interpret text consistently.
Why was Unicode needed?
Different systems once used incompatible character tables. The same number could mean one letter on one computer and another elsewhere. ASCII suited English but lacked Lithuanian letters, many world scripts and emoji.
Unicode created one shared character catalogue. It lets us write in a single text: Labas, Ąžuolas, こんにちは and 🙂.
Code point
The number assigned to a Unicode character is called a code point. It is usually written in hexadecimal with the prefix U+ .
| Character | Code point |
|---|---|
A | U+0041 |
Ą | U+0104 |
€ | U+20AC |
🙂 | U+1F642 |
Unicode specifies which number belongs to a character. A UTF encoding specifies how to store that number as bytes.
Unicode in a Java program
String tekstas = "Ąžuolas 🌳";
int codePoint = tekstas.codePointAt(0);
System.out.println(tekstas);
System.out.printf("U+%04X%n", codePoint);Ąžuolas 🌳
U+0104
In the first line, Java stores Lithuanian text and an emoji. The method codePointAt(0) retrieves the first character's Ą code point, and printf displays it in standard Unicode notation.
Three common Unicode encodings
- UTF-8 – uses 1–4 bytes and is the usual choice on the web.
- UTF-16 – uses one or two 16-bit code units and is closely related to Java's
String. - UTF-32 – stores each code point in 4 bytes: simple, but takes more space.
The Unicode character's value stays the same; only its byte representation changes.