An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.

Slides:



Advertisements
Similar presentations
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
Advertisements

Chapter 7 Strings F To process strings using the String class, the StringBuffer class, and the StringTokenizer class. F To use the String class to process.
1 Strings and Text I/O. 2 Motivations Often you encounter the problems that involve string processing and file input and output. Suppose you need to write.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 8 Strings.
Java Programming Strings Chapter 7.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 9 Strings and Text I/O.
©2004 Brooks/Cole Chapter 7 Strings and Characters.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
The Print Formatting Statement … named printf. 2 Introduction to printf statements print and println statements don’t allow us to easily format output.
Introduction to Objects and Input/Output
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Chapter 9 Characters and Strings. Topics Character primitives Character Wrapper class More String Methods String Comparison String Buffer String Tokenizer.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 9 Characters and Strings (sections ,
COMP 14 Introduction to Programming Miguel A. Otaduy May 17, 2004.
23-Jun-15 Strings, Etc. Part I: String s. 2 About Strings There is a special syntax for constructing strings: "Hello" Strings, unlike most other objects,
Fundamental Programming Structures in Java: Strings.
Strings, Etc. Part I: Strings. About Strings There is a special syntax for constructing strings: "Hello" Strings, unlike most other objects, have a defined.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Odds and Ends Strings (from Chapter 9) StringTokenizer.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 9 Characters and Strings (sections ,
 Pearson Education, Inc. All rights reserved Strings, Characters and Regular Expressions.
Ping Zhang 10/08/2010.  You can get data from the user (input) and display information to the user (output).  However, you must include the library.
Lesson 3 – Regular Expressions Sandeepa Harshanganie Kannangara MBCS | B.Sc. (special) in MIT.
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture 16: Working with Text.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java: Early Objects Third Edition by Tony Gaddis Chapter.
Chapter 9: Text Processing and More about Wrapper Classes Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis.
Java How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Java Methods A & AB Chapter 10 - Strings. Ch 10 Goals Understand Strings indepth Learn strategies to deal with the immutability of Strings Learn how to.
 Pearson Education, Inc. All rights reserved Formatted Output.
1 2 2 Introduction to Java Applications Introduction Java application programming –Display messages –Obtain information from the user –Arithmetic.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Chapter 7 Strings  Use the String class to process fixed strings.  Use the StringBuffer class to process flexible strings.  Use the StringTokenizer.
String Manipulation Chapter 15 This chapter explains the String facilities. You have already seen some of the main methods of the String class.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Strings Carol Yarbrough AP Computer Science Instructor Alabama School of Fine Arts.
Objectives ► Become familiar with the class String ► ► Learn how to use input and output dialog boxes in a program ► ► Learn how to tokenize the input.
Operations on Strings. 8/8/2005 Copyright 2006, by the authors of these slides, and Ateneo de Manila University. All rights reserved L: String Manipulation.
Chapter 7: Characters, Strings, and the StringBuilder.
CHAPTER 9 Text Processing and More about Wrapper Classes Copyright © 2016 Pearson Education, Inc., Hoboken NJ.
10-2 Chapter 10 discusses the following main topics:  Introduction to Wrapper Classes  Character Testing and Conversion with the Character Class  More.
String Handling StringBuffer class character class StringTokenizer class.
Strings Chapter 7 CSCI CSCI 1302 – Strings2 Outline Introduction The String class –Constructing a String –Immutable and Canonical Strings –String.
Jaeki Song JAVA Lecture 07 String. Jaeki Song JAVA Outline String class String comparisons String conversions StringBuffer class StringTokenizer class.
Strings and Text File I/O (and Exception Handling) Corresponds with Chapters 8 and 17.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 10: Text Processing and More about Wrapper Classes Starting.
String String Builder. System.String string is the alias for System.String A string is an object of class string in the System namespace representing.
Strings And other things. Strings Overview The String Class and its methods The char data type and Character class StringBuilder, StringTokenizer classes.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 9 GEORGE KOUTSOGIANNAKIS Copyright: 2014 Illinois Institute of Technology- George Koutsogiannakis 1.
Strings and Related Classes String and character processing Class java.lang.String Class java.lang.StringBuffer Class java.lang.Character Class java.util.StringTokenizer.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Strings A string is a sequence of characters that is treated as a single value. Strings are objects. We have been using strings all along. For example,
28 Formatted Output.
Strings, Characters and Regular Expressions
Strings, Characters and Regular Expressions
Strings, StringBuilder, and Character
Primitive Types Vs. Reference Types, Strings, Enumerations
EE422C - Software Design and Implementation II
Chapter 7: Strings and Characters
MSIS 655 Advanced Business Applications Programming
Lecture 07 String Jaeki Song.
OBJECT ORIENTED PROGRAMMING I LECTURE 9 GEORGE KOUTSOGIANNAKIS
Introduction to Java Applications
CS2011 Introduction to Programming I Strings
Chapter 7 Strings Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. Use the String class to process fixed.
CS 1054 Introduction to Programming in Java
Presentation transcript:

An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting

An Introduction to Java Programming and Object-Oriented Application Development 2 Brief Review of the char Data Type Recall a char is one of eight _________ types A character is any symbol represented by Unicode A char is always expressed inside single quotes Every individual character has an equivalent ________ value The methods of the Character class manipulate characters

An Introduction to Java Programming and Object-Oriented Application Development 3 Brief Review of the char Data Type (continued)

An Introduction to Java Programming and Object-Oriented Application Development 4 Methods in the Character Class The Character class is a __________ class The Integer and Double classes are also wrapper classes Each primitive type has a corresponding wrapper class A wrapper class ‘wraps’ the value of a primitive type within an object so methods can be applied

An Introduction to Java Programming and Object-Oriented Application Development 5 Methods in the Character Class (continued) charValue retrieves the character stored in the Character object compareTo returns the difference in _________ values for two characters equals is true if two characters are identical isDigit is true if a character is in [0-9] isLetter is true if a character is in [a-z or A-Z]

An Introduction to Java Programming and Object-Oriented Application Development 6 Methods in the Character Class (continued) isWhiteSpace is true if the character is a space isWhiteSpace returns false if the character is newline, tab, etc. toLowerCase changes uppercase to lowercase toUpperCase changes lowercase to uppercase

An Introduction to Java Programming and Object-Oriented Application Development 7 Brief Review of the String Class Recall a string is an object –String myStr = “Johnson” –String myStr = new String( “Johnson” ) Recall the methods equals, length and substring A string is a __________ variable that contains the memory address of an array of characters Two classes StringBuilder and StringTokenizer manipulate strings

An Introduction to Java Programming and Object-Oriented Application Development 8 Brief Review of the String Class (continued) StringBuilder provides methods to manipulate and build strings StringTokenizer breaks strings into _______ A token is a group of characters within a string Tokens are separated by ___________ The tokens in this sentence are delimited by white space

An Introduction to Java Programming and Object-Oriented Application Development 9 The StringBuilder Class A String object is ____________ –i.e., once created it can never be changed StringBuilder allows strings to be modified StringBuilder is in the java.lang package All methods in StringBuilder are _________ (i.e., can be called only by objects, not the class)

An Introduction to Java Programming and Object-Oriented Application Development 10 The StringBuilder Class (continued) append adds text to an existing StringBuilder object insert inserts a second argument just after the position given by the first argument deleteCharAt deletes a single character from a StringBuilder at a given position replace replaces all occurrences of one character with another toString creates a _______ that contains the data from the StringBuilder object

An Introduction to Java Programming and Object-Oriented Application Development 11 The StringTokenizer Class StringTokenizer is in the _________ package StringTokenizer breaks a string into tokens –Create the string to be tokenized –Create the StringTokenizer object linked to the string –Apply the StringTokenizer object to the string to get a token nextToken and countTokens are nonstatic

An Introduction to Java Programming and Object-Oriented Application Development 12 The printf and format Methods We have been using System.out.println and string concatenation ( + ) Instead of print and println, you can use printf and format

An Introduction to Java Programming and Object-Oriented Application Development 13 The printf and format Methods (continued)

An Introduction to Java Programming and Object-Oriented Application Development 14 The printf and format Methods (continued)

An Introduction to Java Programming and Object-Oriented Application Development 15 The printf and format Methods (continued) printf takes a format string and a string variable: printf(“Cost: $%.2f\n”, cost ); The format specifier begins with %, ends with a conversion character: %.2f Conversion suffix characters may follow the conversion characters Integers use conversion characters d and x Floating points use conversion characters e, E, f, and g

An Introduction to Java Programming and Object-Oriented Application Development 16 The printf and format Methods (continued) Characters and strings use the conversion characters C and S Dates and times use the conversion character t, possibly with suffix characters C, A, B, d, Y The argument index specifies the argument to which the format specifier applies –$1 is the first, $2 is the second,…, $n is the n th The field width is the number of spaces an argument occupies The precision is the number of decimal places

An Introduction to Java Programming and Object-Oriented Application Development 17 The format Method The printf method displays to the command window printf cannot be used to output to a GUI or file The format method in the Formatter class can output to a GUI or file format is identical to printf

An Introduction to Java Programming and Object-Oriented Application Development 18 The format Method (continued)