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

Do you suspect that characters are important enough to be one of the eight primitive data types?

Answer:

Yes.


The char Primitive Data Type

Computer programs frequently work with character data. The primitive data type for characters in Java is named char. The char type represents a character using 16 bits. In many programming languages, only 8 bits are used for this purpose. Java uses 16 bits so that a very large number of characters can be represented, nearly all of the characters in all of the World's languages. The method used is called Unicode.

For example, here is a 16 bit pattern:

0000000001100111

If you know that these 16 bits are of data type char, then you could look in a table and discover that they represent the character 'g'. If you have a really good memory, you might recall that the same 16 bits represent the integer 103 if they are regarded as data type short. Knowing the data type of a pattern is necessary to make sense of it.

Upper and lower case characters are represented by different patterns. Punctuation and special characters are also char data. There are also special characters, like the space character that separates words.

Control characters are bit patterns that show the end of a line or where to start pages. Other control characters represent the mechanical activities of old communications equipment (such as Teletypes) that are rarely used these days. Many of these control characters are no longer used for their original purpose.

Primitive type char represents a SINGLE character. It does not include any font information. When you want to deal with more than one character at a time (almost always), you need to use objects that have been built out of char data.


QUESTION 13:

Is each of the following a different character?

0       O         o

(Depending on the fonts your browser is using, you may have to look carefully.)