Is each of the following a different character?
0 O o
Yes. Each of the above (zero, Capital 'O', and lower case 'o') is a different character and has its own 16 bit code.
A character literal is a single character with an apostrophe on each side:
'm' 'y' 'A'
A control character is represented with a special sequence of characters:
'\n' '\t'
Each of these represents a single control character. The first one represents the newline character and the second one represents the tabulation character. You will rarely use any control characters other than these two. Several others are listed in the Java documentation.
Warning: The following is not a character literal:
"Hello"
This is a String
, which is not primitive data.
It is, in fact, an object.
Strings
are surrounded by double quote marks "
, not by apostrophes.
What is wrong with the following char
literal:
"W"