Classify the characters in a String
A char is a 16-bit number that stands for one character through the Unicode table, so you can do arithmetic on it. A boolean holds only true or false, and unlike in C it is not a number and never converts to or from one.
Change the code and press Run (Ctrl+Enter). Try to predict the output first, then break it on purpose and read the error. Your edits are saved and match the lesson page.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Print each letter of "java" together with its Unicode number, one per line.
Convert the digit characters in "2026" into the number 2026 without using Integer.parseInt.
Write a program that turns 'h' into 'H' in two ways: with Character.toUpperCase and with arithmetic.
Explain it without notes
What exactly does a char variable store, and why can you do arithmetic on it?
Why does 'A' + 'B' print 131 while "" + 'A' + 'B' prints AB?
Why does Java refuse if (count) and boolean b = 1; when C accepts them?
What is a surrogate pair, and why does it make length() misleading for some text?
Expected output
letters=10 digits=2 spaces=2 other=1 upper=2
toUpperCase('q') = Q
getNumericValue('9') = 9