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

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.

Character Literals

In a program, a character literal is surrounded with an apostrophe on both sides:

'm'          'y'               'A'

In a program, control characters are represented with several characters inside the apostrophes:

'/n'          '/t'

Each of these is what you do in a program to get a single char. The first one represents the 16 bit 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:


This is, in fact, a String, which is not primitive data. Strings are surrounded by double quotes ", not by apostrophes.


What is wrong with the following char literal: