Completion requirements
This chapter discusses eight primitive data types in Java.
14. Character Literals
Answer:
Yes. Each of the above (zero, Capital 'O', and lower case 'o') is a different character
and has its own 16 bit code.
Character Literals
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.
Question 14:
What is wrong with the following
char
literal:
"W"