# Why Java's char Type Does Not Represent All Unicode Characters

DevFeed: [Why Java's char Type Does Not Represent All Unicode Characters](<https://devfeed.tech/articles/the-char-type-in-java-is-broken-24942.md>)

Original publisher: [Read original article](<https://codeahoy.com/2016/05/08/the-char-type-in-java-is-broken/>)

Author: umer

Published: 2016-05-08T00:00:00Z

Content type: opinion

Language: en

Sources: [Code Ahoy - Articles](<https://devfeed.tech/sources/code-ahoy-articles.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [java](<https://devfeed.tech/tags/java.md>), [opinion](<https://devfeed.tech/tags/opinion.md>)

## AI overview

The article explains that Java's char type stores 16-bit values, while Unicode includes characters requiring more than 16 bits. It contrasts char with Java strings using UTF-16 and warns that character-processing methods can mishandle characters such as emojis.

## Source excerpt

If I may be so brash, it is my opinion that the char type in Java is dangerous and should be avoided if you are going to use Unicode characters. char is used for representing characters (e.g. 'a', 'b', 'c') and has been supported in Java since it was released about 20 years ago. When Java first came out, the world was a simpler place. Windows 95 was the latest, greatest operating system, world's first flip phone was just put on sale, and Unicode had less than 40,000 characters, all of which fit perfectly into the 16-bit space that char provides. But things have changed drastically. Unicode has outgrown the 16-bit space and now requires 21 bits for all of its 120,737 characters. Java has supported Unicode since its first release and strings are internally represented using UTF-16 encoding. UTF-16 is a variable length encoding scheme. For characters that can fit into the 16 bits space, it uses 2 bytes to represent them. For all other characters, it uses 4 bytes. This is great. All possible Unicode characters in existence plus a lot more (1 million more) could be represented using UTF-16 and thus as Strings in Java. But char is a different story altogether. Let's look at its definition from the official source: char: The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive). "16-bit Unicode character"? I guess Joel was right: Some people are under the misconception that Unicode is simply a 16-bit code where each character takes 16 bits and therefore there are 65,536 possible characters. This is not, actually, correct. It is the single most common myth about Unicode, so if you thought that, don't feel bad. There is no such thing as "16-bit Unicode character". Please read Joel's article if you don't understand the last statement. char uses 16 bits to store Unicode characters that fall in the 0 - 65,535 which isn't enough to store all Unicode characters anymore. You might think: