Unicode & the char Type in Java
Java's char type holds exactly one 16-bit Unicode character — not one byte, unlike C's char — which is why Java can represent characters from far more of the world's scripts than a single-byte encoding ever could. Internally, a char is really just a 16-bit unsigned integer, and Java freely lets you treat it as one: adding 1 to a char moves to the next code point, and a char can be assigned directly from an int literal that fits in that range.
Because a 16-bit value can only reach about 65,536 distinct code points, and Unicode itself now defines far more characters than that, some characters outside the common range need a pair of char values — called a surrogate pair — to represent a single visual character. One everyday consequence is that String.length() can occasionally report a different count than the number of visual characters a person would actually see.
A char is 16 bits
Java's char always occupies 16 bits, holding one UTF-16 code unit — a deliberate design choice for broader script support than a single byte allows.
Chars behave like small integers
Arithmetic works directly on a char: 'A' + 1 evaluates to the int 66, and adding a char to an int promotes the whole expression to int.
Character literals versus escape codes
A char can be written as a quoted letter like 'A', or as a Unicode escape like '\u0041', which represents the exact same character.
Casting between char and int
(char) 66 converts the integer 66 back into the character 'B'; the conversion is entirely mechanical, just reinterpreting the same numeric value.
Surrogate pairs
Characters outside the Basic Multilingual Plane need two char values together to represent one visual character, which is why String.length() can occasionally disagree with the number of characters a person would count on screen.
public class CharDemo { public static void main(String[] args) { char letter = 'A'; int code = letter + 1; char next = (char) code; System.out.println("Letter: " + letter + ", code: " + (int) letter); System.out.println("Next letter: " + next); }}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Java yourself — building beats watching.