The flashcards below were created by user CarlyUSC13 on FreezingBlue Flashcards.

  1. To read input from a disk file the ____ class relies on another class, File, which describes disk files and directories. 
  2. To write output to a file, you construct a ____ object.
  3. If the output file already ____, it is emptied before the new data are written into it. If the file doesn't exist, an empty file is ____. 
    • exists
    • created
  4. You must close a print stream when you are done writing output. How to do that is:
  5.  ___ delimiters so that the program can be used for numbering Java source files. 
  6. When the input or output file doesn't exist, a _____  can occur. The compiler insists that we tell it what the program should do when that happens. 
  7. You must simply remember to use File objects in the Scanner constructor:
    Scanner in = new Scanner(new File("input.txt")); 
  8. In Java, word is not the same as in English. It is any sequence of characters that is not____.
    white space. 
  9. Sometimes, you want to read just the words and discard anything that isn't a letter. You achieve this task by calling the useDelimiter method on your Scanner object as follows:
    • Scanner in = new Scanner( ... );
    • in.useDelimeter("[^A-Za-z])+");

    With this setting, punctuation and numbers are stripped off from the words returned by the next method. 
  10. The nextLine method reads a line of input and consumes the newline character at the end of the line.
    When each line of a file is a data record, it is often best to read entire lines with the nextLine method:

    String line = in.nextLine();
  11. Use the isDigit and isWhitespace methods to find out where the name ends and the number starts.
    Locate the first digit:

    • int i = 0;
    • while (!Character.isDigit(line.charAt(i))) {i++}
  12. The nextInt and nextDouble methods consume white space and the next number.
    double value = in.nextDouble();

    To avoid exceptions, use the hasNextDouble method to screen the input. For example:
    • if (in.hasNextDouble())
    • {
    •    double value = in.nextDouble();
    • }

    NOTE: The nextInt and nextDouble methods do not consume the white space that follows a number. 
  13. To read one character at a time, set the delimeter pattern to the ____. 
    Empty String
  14. There are two main aspects to exception handling: ____.
    Reporting and Recovering. 
  15. To signal an exceptional condition, use the ___ statement to throw an exception object. 
  16. When you throw an exception, the current method___.
    Terminates immediately
  17. When you throw an exception, execution does not contnue with the next statement but with an _____.
    exception handler
  18. Java exceptions fall into two categories; ____ and ____ exceptions. 
    • checked
    • unchecked
  19. Checked Exceptions
    Check exceptions are due to external circumstances that the programmer cannot prevent. The compiler checks that you don't ignore it. You must tell the compiler what you are going to do about the exception if it is ever thrown. For example all subclasses of IOException are checked exceptions. 
  20. Unchecked Exceptions
    The compiler does not require you to keep track of unchecked exceptions. Unchecked exceptions extend the class RuntimeException or Error. Exceptions such as NumberFormatException, IllegalArgument-Exception, and NullPointerException are uncheckedexceptions. More generally, all exceptions that belong to subclasses of RuntimeException are unchecked, and all other subclasses of the class Exception are checked. 
  21. Why have two kinds of exceptions?
    A checked exception describes a problem that is likely to occur at times, no matter how careful you are. The unchecked exceptions, on the other hand, are your fault. 
Card Set:
2012-11-09 04:15:07
java big comp121

Second Test for Computer Science 121 at Franklin University
Show Answers: