String Literals

   

The char primitive supports variables that represent a single character. Sequences of characters are not represented by a primitive type in Java, but by a reference type, the String class, instead. This class is discussed in Chapter 8, "Using Strings and Text," but you need to know a little about strings now to finish the discussion of literals. String literals contain zero or more characters enclosed in double quotation marks. These characters can include the escape sequences listed in the "Character Literals" section earlier in this chapter. Both double quotation marks must appear on the same line of the source code, so strings cannot directly contain a new line character. To achieve the new line effect, you must use an escape sequence such as \ n within the string. The double-quotation mark ( " ) and backslash ( \ ) characters must also be represented using escape sequences ( \ " and \ ) within a string literal.

Some examples of string literals include

 "Java" "Hello World!\ n" "The Devanagari numeral for 9 is \ u096f " 
   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

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