Data Type: Character

The char data type stores one Unicode character. Because Unicode characters are encoded as unsigned numbers using 16 bits, a char variable is stored in two bytes of memory. The second table below shows the size of the char data type, as well as the minimum and maximum values. The maximum value is the unsigned hexadecimal number FFFF, which is reserved as a special code for “not a character.”

Screen Shot 2018-12-10 at 8.21.12 AM

Screen Shot 2018-12-10 at 8.22.49 AM

Obviously, since the char data type can store only a single character, such as a K, a char variable is not useful for storing names, titles, or other text data. For text data, Java provides a String class, which we’ll discuss later in a later post.

Here are a few declarations of char variables:

Screen Shot 2018-12-10 at 8.28.24 AM

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s