mat 2170
play

Mat 2170 ASCII Table Week 11 Character Methods Arithmetic - PowerPoint PPT Presentation

Mat 2170 Week 11 Characters and Strings char Mat 2170 ASCII Table Week 11 Character Methods Arithmetic Characters and Strings String Equality Test char vs String Spring 2014 Searching Methods Patterns Exercises Pig Latin Student


  1. Mat 2170 Week 11 Characters and Strings char Mat 2170 ASCII Table Week 11 Character Methods Arithmetic Characters and Strings String Equality Test char vs String Spring 2014 Searching Methods Patterns Exercises Pig Latin

  2. Student Responsibilities Reading: Textbook, Sections 8.2–8.4 Mat 2170 Week 11 Lab: Character and String processing Characters and Strings Attendance char Surely you don’t think that ASCII Table numbers are as important as words. Character King Azaz to the Mathemagician Methods Arithmetic The Phantom Tollbooth , 1961, by Norton Juster String Equality Test Chapter Eight Overview char vs String 1. Characters - the primitive type char Searching 2. Strings as an abstract idea Methods Patterns 3. Using methods in the String class Exercises 4. A case study in string processing Pig Latin

  3. Characters Mat 2170 Week 11 The primitive type char can store a single character. Characters and Strings There are a finite number of characters on the keyboard. char ASCII Table [Collating Sequence] If we assign an integer to each Character character , we can use that integer as a code for the Methods character it represents. Arithmetic String Equality Test Character codes are not particularly useful unless they are char vs standardized . String Searching If different computer manufacturers use different coding Methods sequences (as was the case in the ”early” years), it is harder Patterns to share such data across machine platforms. Exercises Pig Latin

  4. ASCII Mat 2170 Week 11 Characters and Strings The first widely adopted character encoding was ASCII — American Standard Code for Information Interchange . char ASCII Table Character With only 256 possible characters (the number of bit Methods combinations in a byte), the ASCII system proved inadequate Arithmetic to represent the many alphabets in use throughout the world. String Equality Test char vs String It has therefore been superseded by Unicode , which allows for Searching a much larger number of characters. Methods Patterns Exercises Pig Latin

  5. The ASCII Subset of Unicode The first 128 characters — written in Octal or Base 8 Mat 2170 Week 11 0 1 2 3 4 5 6 7 base Characters 000 \ 000 \ 001 \ 002 \ 003 \ 004 \ 005 \ 006 \ 007 and Strings \ b \ t \ n \ 013 \ f \ r \ 016 \ 017 010 \ 020 \ 021 \ 022 \ 023 \ 024 \ 025 \ 026 \ 027 020 char 030 \ 030 \ 031 \ 032 \ 033 \ 034 \ 035 \ 036 \ 037 ASCII Table 040 space ! " # $ % & ’ Character 050 ( ) * + , - . / Methods 060 0 1 2 3 4 5 6 7 Arithmetic 070 8 9 : ; < = > ? String 100 @ A B C D E F G Equality Test 110 H I J K L M N O char vs String 120 P Q R S T U V W Searching 130 X Y Z [ \ ] ^ _ Methods 140 ‘ a b c d e f g Patterns 150 h i j k l m n o Exercises 160 p q r s t u v w Pig Latin ∼ 170 x y z { | } \177

  6. Notes on Character Representation Mat 2170 Week 11 Characters and Strings There is NO reason to memorize underlying numeric codes char ASCII Table for the characters Character Methods Arithmetic String The important observation is that each character has a Equality Test numeric representation — not what that representation char vs happens to be. String Searching Methods Patterns Exercises Pig Latin

  7. Character Constants Mat 2170 Week 11 Characters To specify a character in a Java program use a character and Strings constant which consists of the desired character enclosed in char single quotation marks. Don’t use the numeric code! ASCII Table Character Methods The constant ’A’ in a program indicates the Unicode Arithmetic representation of an uppercase A . String Equality Test char vs String That an uppercase A has the value 101 8 is an irrelevant Searching detail — use the character, not the collating sequence code Methods value. Patterns Exercises Pig Latin

  8. Properties of Unicode Mat 2170 Week 11 Characters Two properties of the Unicode table worth special notice : and Strings char ASCII Table Character The character codes for the digits are consecutive Methods Arithmetic String The letters in the alphabet are divided into two ranges : one Equality Test for the uppercase letters and one for the lowercase letters. char vs String Searching Within each range of alphabetic letters, the Unicode values Methods are consecutive . Patterns Exercises Pig Latin

  9. Special Characters Mat 2170 Week 11 Characters Most of the characters in the Unicode table are familiar ones and Strings that appear on the keyboard. char ASCII Table Character These characters are called printing (or printable ) characters. Methods Arithmetic The table also includes several special characters that are String Equality Test typically used to control formatting — for example, ’ \ n’. char vs String Searching Special characters are indicated by an ” escape ” sequence: Methods a backslash followed by a character or sequence of digits. Patterns Exercises Pig Latin

  10. The Most Common Special Characters Mat 2170 \b Backspace Week 11 Characters Form feed — starts a new page \f and Strings moves to the next line — ( Newline ) \n char \r Return — moves to the beginning of the current ASCII Table line without advancing Character Tab — moves horizontally to the next tab stop Methods \t Arithmetic \\ The backslash character itself String The character ’ — required only in character \’ Equality Test constants char vs String The character ” — required only in string con- \" Searching stants Methods \ddd The character whose Unicode value is the octal Patterns number ddd Exercises Pig Latin

  11. The Character Class Mat 2170 Week 11 Characters and Strings The Character class is defined in the java.lang package and char ASCII Table is therefore available in any Java program without an import Character statement. Methods Arithmetic String Equality Test The Character class provides several useful methods for char vs manipulating char values. String Searching Methods Patterns Exercises Pig Latin

  12. The Character Class Mat 2170 Week 11 Characters and Strings Character methods are static — they belong to the entire char class, rather than to any particular object of the class. ASCII Table Character Methods These methods can be used with char objects — similar to Arithmetic Math class methods and how they work on numeric types. String Equality Test char vs It is good programming practice to use these library methods String rather than writing our own. Searching Methods Patterns Exercises Pig Latin

  13. Why Use Character Class Methods Mat 2170 Week 11 They are standard — programmers recognize them and know Characters and Strings what they mean. char ASCII Table Library methods have been tested by millions of client Character programmers, so it is reasonable to expect that they are Methods correct . Arithmetic String Implementations in the Character class are able to convert Equality Test characters in alphabets other than our Roman (English) char vs alphabet. String Searching Methods Library methods are typically more efficient than methods we Patterns write ourselves. Exercises Pig Latin

  14. Useful Static Methods in the Character Class Mat 2170 static boolean isDigit(char ch) Week 11 Determines if the specified character is a digit. Characters and Strings static boolean isLetter(char ch) char Determines if the specified character is a letter. ASCII Table static boolean isLetterOrDigit(char ch) Character Determines if the specified character is a letter or digit. Methods Arithmetic static boolean isLowerCase(char ch) String Determines if the specified character is a lowercase letter. Equality Test static boolean isUpperCase(char ch) char vs Determines if the specified character is an uppercase String Searching letter. Methods static boolean isWhitespace(char ch) Patterns Determines if the specified character is whitespace — Exercises spaces or tabs. Pig Latin

  15. Two Which Return char Rather Than boolean Mat 2170 Week 11 static char toLowerCase(char ch) Characters and Strings Returns a copy of ch converted to its lowercase equivalent, if any. char Otherwise, the value of ch is returned unchanged. ASCII Table Character Methods static char toUpperCase(char ch) Arithmetic Returns a copy of ch converted to its uppercase String equivalent, if any. Equality Test Otherwise, the value of ch is returned unchanged. char vs String Searching Methods Patterns Neither of these methods modifies the char Exercises argument sent to the method. Pig Latin

  16. Character Arithmetic Mat 2170 The fact that characters have underlying integer Week 11 representations allows us to use them in arithmetic Characters and Strings expressions . char ASCII Table For example, if you evaluate the expression ’A’ + 1 , Java will Character convert the character ’A’ into the integer 65 and then add 1 Methods to get 66, which is the character code for ’B’ Arithmetic String As an example, the following method returns a randomly Equality Test char vs chosen uppercase letter—why is the (char) in the return String statement? Searching Methods public char randomLetter() { Patterns return (char) rgen.nextInt(’A’, ’Z’); Exercises } Pig Latin

Recommend


More recommend