Chapter 8 Characters and strings 2000 McGraw-Hl‖ Introduction to Object-Oriented Programming with Java-Wu Chapter 8-1
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 8 - 1 Chapter 8 Characters and Strings
Chapter 8 Objectives After, you have read and studied this chapter, you shoula be able to Declare and manipulate data of the char data type e Write string processing programs using String ang String Buffer objects. e Differentiate the string and String Buffer classes and use the correct class in solving a given task e Distinguish the primitive and reference data types and show how the memory allocation between the two is different e Tell the difference between equality and equivalence testings for String objects Show by using the state-of-memory diagrams how objects are passed to methods and returned from methods C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 8-2
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 8 - 2 Chapter 8 Objectives After you have read and studied this chapter, you should be able to Declare and manipulate data of the char data type. Write string processing programs using String and StringBuffer objects. Differentiate the String and StringBuffer classes and use the correct class in solving a given task. Distinguish the primitive and reference data types and show how the memory allocation between the two is different. Tell the difference between equality and equivalence testings for String objects. Show, by using the state-of-memory diagrams, how objects are passed to methods and returned from methods
Characters rIn 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 rTo represent characters in computer, U. s computer manufacturers devised several coding schemes r One coding scheme widely used today is ASCII American Standard code for information Interchange) rTo accommodate the character symbols of non- English languages, the Unicode Consortium established the Unicode Worldwide character Standard, commonly known as Unicode C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 8-3
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 8 - 3 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 coding schemes. One coding scheme widely used today is ASCII (American Standard Code for Information Interchange). To accommodate the character symbols of nonEnglish languages, the Unicode Consortium established the Unicode Worldwide Character Standard, commonly known as Unicode
ASCII Table 0 nul soh stx eot ac k bel b ht 10 If vt ff si dle dcl dc2 dc3 2 ak can ett b esc %& 40 ? @ A B C E For example character 'O'is G H K L M 79(row value T 70+ col value 9 80 79) d 1 k 120 del C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 8-4
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 8 - 4 ASCII Table For example, character 'O' is 79 (row value 70 + col value 9 = 79). O 9 70
Character processing char chl, ch2 Declaration and initialization messageBox. show("ASCII code of character x is+ (int) Type conversion message. show("Character with AsCII code 88 is+ between int and char. (char)88 This comparison returns true because ascll value of a is 65 while that of 'c' is 99 C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 8-5
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 8 - 5 Character Processing Declaration and initialization char ch1, ch2 = ‘X’; Type conversion between int and char. messageBox.show("ASCII code of character X is " + (int) 'X' ); message.show("Character with ASCII code 88 is " + (char)88 ); This comparison returns true because ASCII value of 'A' is 65 while that of 'c' is 99. ‘A’ < ‘c’