Computer Science (CSCI) Department
College of Engineering, Computer Science, & Technology (ECST)

JETT Workshops
Java Basics

Fall 2004

 

Strings
(Example code and figures from Computing Concepts with Java Essentials, 3rd edition, by Cay Horstmann.
Visit www.wiley.com/college/horstmann for information on the current edition of this excellent text.)

  • from the AP CS Java Subset
    • Students need not be aware that strings are composed of char values.
      • Introducing char does not increase the expressiveness of the subset.
      • Not introducing char avoids complexities with the char/int conversions and confusion between "x" and 'x'.
    • Students need to understand string concatenation, String.substring, and String.equals.
    • String concatenation + is part of the AP Java subset.
      • Students are expected to know that concatenation converts numbers to strings and invokes toString on objects.
      • String concatenation can be less efficient than using the StringBuffer class.
      • However, for greater simplicity and conceptual clarity, the StringBuffer class is not in the subset.
    • The escape sequences inside strings \\, \", \n are part of the AP Java subset.
      • The \t escape and Unicode \uxxxx escapes are not in the subset.
      • The \' escape is only necessary inside character literals and is not in the subset.
    • Processing string input (e.g., with StringTokenizer) and converting strings to numeric values (e.g., with Integer.parseInt) is not in the subset.

Exercise - play with Strings in the Greeter project

  • use the Greeter project
  • play with Strings
    • create some more strings
    • look up the String class in the API
    • try out some of the methods