Nearby lessons
14 of 125Java - Unicode System
- Understand why Java uses Unicode
- Learn that a Java char is 2 bytes (16 bits)
- Use unicode escape sequences \uXXXX
Learn how Java handles text from every language in the world using the Unicode system — a unique number for every character, stored in a 16-bit char.
What is Unicode?
Computers only understand numbers. To show text, every character must be given a unique number. Unicode is the international standard that assigns a unique number to every character of every language — English, Hindi, Chinese, Arabic, emojis and more.
Java char is 16 bits
In C/C++ a char is 1 byte (8 bits) — enough for 256 characters, which is fine for English but not for the world's scripts. Java's char is 2 bytes (16 bits), able to store 65,536 different characters. That is why a Java program can print text in any language.
Unicode Escape Sequences (\uXXXX)
You can write any character by its Unicode number using the \uXXXX escape — XXXX is the 4-digit hexadecimal code:
Key Points
char= 2 bytes = 16 bits in Java.- The first 128 codes match the old ASCII table, so English text looks the same.
\uXXXXwrites a character by its hexadecimal Unicode number.- Unicode is why Java is called a language-independent platform — one program can show any language.
- Unicode gives every character in every language a unique number
- A Java char stores 16 bits — enough for 65,536 characters
- Write any character with the \uXXXX escape sequence