Do you suspect that characters are important enough to be one of the eight primitive data types?
Yes.
char
Primitive Data Type
Characters are very common in computers.
The primitive data type
for characters 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:
000000000110011
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.
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.)