Java Chapter 10

Ch 10 test review.

  1. Know the 14 APIs:
String APIs:   1.Endswith 2. Substring 3.CharAt 4.indexOf 5.trim 6.lastIndexOf 7. Length 8. Replace 9. Equals 10.
Character wrapper class: isDigit 11. isUpperCase 12. isLowerCase 13. isWhiteSpace 14. isLetter
Other wrapper classes: ParseInt, ParseDouble, toString

  1. What is an Index Out of Range Exception? Give an example of a code where your program encounters it.
The character is beyond the number of characters in a string.
(the length of a string is 10 and the character is at 11)
  2. What is wrong with this code? Its purpose is to print a message vertically.

charPos should be initialized to 0
public   void printMsg()
String message = “Subscribe to TelCO and save!!!”
int charPos = 1;
charPos is e.message.length() therefore it would be out of range
while (charPos <= message.length())
charPos = charPos + 1;

  3. What is an immutable class? What are the advantages and disadvantages of an immutable class? An immutable class is a class that cannot be changed.
Advantage: stays the same
Disadvantage: harder for the programmer (each time it should be changed, another new string must be made)

What is the advantage of immutability as it applies to the String class? The disadvantages ?

What must you do to make a class immutable?
Use the keyword final
Do you have to use the finalize keyword?
  4. What is a wrapper class? What are some examples and their methods?   What is the purpose of a wrapper class?
A wrapper class provides more methods and functionality to primitive types.
Example: intx, int y )

  5. Do the repeatLetters program in the Study Guide PowerPoint. Paste this into StringUpdatedCollatedTests to test:

System.out.println("Input: \"Noodles\" Output:true "
+ StringToolBox.repeatedLetters("noodles") );
        System.out.println("Input: \"computers\" Output:false "...