Lecture 36, CS 302-7 and 8, April 20

  1. Various things
    1. Program 3

                                                               i.      Due tonight

  1. Review:
    1. Parsing text from files

                                                               i.      Reading word-by-word

1.      Custom delimiters

  1. Reading/Parsing lines of text
    1. Option one – parse the String directly using String, Character, and number methods

                                                               i.      boolean Character.isDigit()

1.      Is this character a number between 0 and 9?

                                                             ii.      boolean Character.isWhiteSpace()

1.      Is this a whitespace character?

                                                            iii.      String string.trim()

1.      Removes whitespace from beginning and end of string

a.       This includes newlines

                                                           iv.      int Integer.parseInt()

1.      What if it’s not an int?  Or even if it contains whitespace…

    1. Option two – new Scanner(String s);
    2. Option three – split String

                                                               i.      String[] string.split(String delim);

1.      Returns an array containing the individual pieces of the String according to the delimiter we pass in

2.      like with useDelimiter, we specify what to split around

a.       Another example of a regular expression

3.      We’ll usually use something like “” or “,”

  1. EmailReader.java
  2. A more general view of exception handling
    1. Detection

                                                               i.      Recognizing that an exception has occurred.  For instance, unable to open the filename specified.

    1. Handling

                                                               i.      Doing something productive with that exception

                                                             ii.      What exactly this means will depend on the context of the exception

1.      Different exceptions/situations require different handling.

    1. Exceptions are Classes that we create objects from.  There is a hierarchy of exceptions that we will discuss in a week or two.  Some are more specific versions of others while some, such as Exception, are very general.