Docsity

Understanding Strings and Characters in Java Programming with String and StringBuffer, Slides of Applications of Computer Sciences

Partial preview of the text

Download Understanding Strings and Characters in Java Programming with String and StringBuffer and more Slides Applications of Computer Sciences in PDF only on Docsity!

Chapter 7:

Strings and Characters

Object-Oriented Program

Development Using Java: A

Class-Centered Approach

Objectives

  • The String Class
  • String Processing
  • The StringBuffer Class
  • Program Design and Development: Program Performance Measures and Object-Oriented Technology (OOT)
  • Common Programming Errors

Creating a String

  • Syntax:

String identifier = new String(string-value);

String identifier; identifier = new String(string-value);

String identifier = string-value;

Creating a String (continued)

  • Storage for a string is created in memory when a string is created - Location of where the string is stored is placed in a variable
  • Called a reference variable

Constructors

  • Instantiating an object is the process of using the new operator to create an object
  • The name of the constructor method must be the same name as the class
  • The String class provides nine different constructors for creating String objects

String Processing

  • Strings are manipulated using:
    • Standard String class methods
    • Character-at-a-time methods provided by the Character class

Other String Methods

  • The charAt() method permits you to retrieve individual characters in a string
  • The last position is always one less than the number of characters in the string

The StringBuffer Class

(continued)

  • String class
    • Preferred class for displaying or comparing strings that tend to remain constant
  • StringBuffer class
    • Should be used for applications that require:
      • Individual character additions
      • Modifications
      • Multiple text edits