characters in java single characters are represented using the data type char. character constants...

7
Characters In Java single characters are represented using the data type char. Character constants are written as symbols enclosed in single quotes, for example, 'a', 'X', and '5'. To represent characters in computer, U. S. computer manufacturers devised several schemes for encoding characters as integers. One coding scheme widely used today is ASCII (American Standard Code for Information Interchange).

Upload: claire-stephens

Post on 30-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Characters In Java single characters are represented using the data type char. Character constants are written as symbols enclosed in single quotes, for

Characters

In Java single characters are represented using the data type char. Character constants are written as symbols enclosed in single quotes, for example, 'a', 'X', and '5'.

To represent characters in computer, U. S. computer manufacturers devised several schemes for encoding characters as integers.

One coding scheme widely used today is ASCII (American Standard Code for Information Interchange).

Page 2: Characters In Java single characters are represented using the data type char. Character constants are written as symbols enclosed in single quotes, for

ASCII Table

For example, character 'O' is 79 (row value 70 + col value 9 = 79).

For example, character 'O' is 79 (row value 70 + col value 9 = 79).

O

9

70

Page 3: Characters In Java single characters are represented using the data type char. Character constants are written as symbols enclosed in single quotes, for

Character Translation

Declaration and initialization

Declaration and initialization

char ch1, ch2 = ‘X’;

Type conversion between int and char.

Type conversion between int and char.

System.out.println("ASCII of X is " + (int) 'X' );

System.out.println("Char 88 is " + (char)88 );

Erf … out to reality ASCIITranslate.java

Page 4: Characters In Java single characters are represented using the data type char. Character constants are written as symbols enclosed in single quotes, for

Character Comparison

This comparison returns true because ASCII value of 'A' is 65 while that of 'c' is 99.

This comparison returns true because ASCII value of 'A' is 65 while that of 'c' is 99.

‘A’ < ‘c’

Spling … out to reality CharOrder.java

Page 5: Characters In Java single characters are represented using the data type char. Character constants are written as symbols enclosed in single quotes, for

Special Characters

These are also known as “escape characters”

Written using a \ prefix

\t \n \b \g \’ \\

Spling … out to reality EscapeCharacters.java

Page 6: Characters In Java single characters are represented using the data type char. Character constants are written as symbols enclosed in single quotes, for

The Character Class

The Character class in the java.lang package includes methods for manipulating character values.

Example, use isLetter to check if a character is a-z or A-Z

Zzzznicka … out to reality … CharGames.java

Zzzznicka … out to reality … CharGamesCompressed.java

Page 7: Characters In Java single characters are represented using the data type char. Character constants are written as symbols enclosed in single quotes, for

Unicode

To accommodate the character symbols of non-English languages, the Unicode Consortium established the Unicode Worldwide Character Standard, commonly known as Unicode.