Java Char Keyword

Java Char Keyword


Char Keyword In Java
  • char in Java is not the same as char in C or C++. In C/C++, char is 8 bits wide.
  •  This is not the case in Java. Instead, Java uses Unicode to represent characters. Unicode defines a fully international character set that can represent all of the characters found in all human languages.
  •  It is a unification of dozens of character sets, such as Latin, Greek, Arabic, Cyrillic, Hebrew, Katakana, Hangul, and many more. For this purpose, it requires 16 bits.
  •  Thus, in Java char is a 16-bit type.
  •  The range of a char is 0 to 65,536.
  •  There are no negative chars.
  •  The standard set of characters known as ASCII still ranges from 0 to 127 as always, and the extended 8-bit character set, ISO-Latin-1, ranges from 0 to 255. 
  • Since Java is designed to allow programs to be written for worldwide use, it makes sense that it would use Unicode to represent characters. Of course, the use of Unicode is somewhat inefficient for languages such as English, German, Spanish, or French, whose characters can easily be contained within 8 bits.
  • char is a keyword in java hence it will be written in small cases always otherwise it will through an error message.
  •  It will always be written in single quotes ‘ ’.
Now we will see an example - 
Example -  In the following example, we will see what happens when we assign an integer value to a character typer variable here we are assigning the ASCII code of X to a char type variable.
Output  -