Nearby lessons

14 of 125

Java - Unicode System

📌 What You Will Learn
  • 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.

In simple words: Unicode is one giant phone book for characters — every symbol in the world has its own number, so text never gets mixed up.

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.

Example02
Loading editor…

Unicode Escape Sequences (\uXXXX)

You can write any character by its Unicode number using the \uXXXX escape — XXXX is the 4-digit hexadecimal code:

Example03
Loading editor…

Key Points

  • char = 2 bytes = 16 bits in Java.
  • The first 128 codes match the old ASCII table, so English text looks the same.
  • \uXXXX writes a character by its hexadecimal Unicode number.
  • Unicode is why Java is called a language-independent platform — one program can show any language.
📝 Key Takeaways
  • 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

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.