go to previous page   go to home page   go to next page hear noise highlighting

Is each of the following a different character?

0       O         o

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"

go to previous page   go to home page   go to next page