CIT 591 Fifth Quiz
Fall 2001, Dave Matuszek
Name:   Answer Key
  1. The connection between your program and a source of data is called a stream .

  2. Before you use a file, you must open it; when you are done, you must close it.

  3. Forcing the contents of a buffer to be written to an output file immediately is called flushing the buffer.

  4. If vec is a Vector containing only Strings, and str is a String,
    1. Write a statement to put str into the Vector:
                vec.add(str);

    2. Write a statement to set str to the String at location 2 in the Vector:
                str = (String)vec.elementAt(2);
                str = (String)vec.get(2);

  5. What is the immediate superclass of Exception?          Throwable

  6. What subclass of Exception represents exceptions that do not need to be caught?     RuntimeException

  7. Write the shortest possible statement that does the same thing as  s = new Integer(n).toString();
              s = n + "";
  8. To comment out a block of code,
    1. What kind of comments are recommended by the Style book?
                /*     */
                "C-style" comments

    2. What kind of comments does the BlueJ Comment command use?
                //
                One-line comments

  9. The instructor covered three good uses for end-line comments; tell one of them.
              Commenting a local variable
              After a closing brace, telling what it closes
              After an else, telling what is true in this case

  10. Under what circumstances will the test str.equals("XYZ") give a different result from "XYZ".equals(str) ?
              When str is null

  11. Why is p.add(okButton, BorderLayout.NORTH); better than p.add(okButton, "North"); ? (Both are legal.)

              Better error checking; if you misspell the direction name, the first gives you a syntax error, the second doesn't.

  12. In the test x instanceof y, what kind of operand would you use for y?
              The name of a class or the name of an interface

  13. Write a statement that puts the char ch into the Vector charVec.
              charVec.add(new Character(ch));

  14. How do you prevent a method from being overridden in a subclass?
              Mark it as final

  15. If an exception occurs in your program, what method call can you put in a catch clause to print out where you were when the error occurred?
              e.printStackTrace();

  16. Name two subclasses of TextComponent.          TextArea     TextField