The String Class


The String Class

Almost every example in this book will make use of String objects. A String object represents a sequence of Unicode characters . It is the basic mechanism that you will use to read, transmit, display, and name data. For example, a class that represents a metal object might define the following field as one of its members .

 private String elementName = "copper"; 

The String class is defined in the java.lang package. The class declaration is:


public  final  class  String  extends  Object  implements  Serializable,  Comparable,  CharSequence

The String class is a direct subclass of the Object class. It belongs to the java.lang package. Remember that java.lang is implicitly imported into every Java program so you always have access to the String class. The String class is final , meaning you can't override it or change its implementation in any way. Strings are so important to the implementation of Java that the developers of the language didn't want anyone to mess with the class.

Strings are immutable objects. This is done for performance reasons since a constant object requires less system overhead than one that can be modified. Once initialized , a String object cannot change the sequence of characters that it represents. Methods used to modify a String object actually create a new String object.



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net