Programming 2 Exam 2

  1. Which of the following statements regarding the throw point of an exception is false?
    It specifies the point at which the exception must be handled.

    True: It is the initial point at which the exception occurs.It is specified as the top row of the method-call stack at the time the exception occurred.
  2. When an unchecked exception occurs in a method but is not caught, ________.
    the method-call stack is "unwound"the method terminatesall local variables in that method go out of scope
  3. After a finally block has finished executing (and there are no exceptions to be handled), ________.
    control proceeds to the first statement after the finally block
  4. To catch an exception, the code that might throw the exception must be enclosed in a ________.
    try block
  5. Which of the following statements is true? Ch 11 No 5
    None of these are true.Answers:The code in a finally block is executed only if an exception occurs.The code in a finally block is executed only if an exception does not occur.The code in a finally block is executed only if there are no catch blocks. None of these are true.
  6. In Java, after an exception is handled, control resumes ________. This is known as the ________ model of exception handling.
    after the last catch block (or the finally block, if there is one), termination
  7. Which of the following statements is false? Ch 11 No 7
    Exception handling can catch but not resolve exceptions.

    true: Exception handling enables programmers to write robust and fault-tolerant programs.Exception handling can resolve exceptions.
  8. Which of the following statements is true? Ch 11 No 9
    The throw statement is used to throw an exception.
  9. What is the difference between a try block and a try statement?
    The try block refers to the keyword try followed by a block of code. The try block and its corresponding catch and/or finally clauses together form a try statement.
  10. Chained exceptions are useful for finding out about ________.
    an original exception that was caught before the current exception was thrown
  11. All exception classes inherit, either directly or indirectly, from ________.
    class Throwable
  12. An uncaught exception ________.
    is an exception that occurs for which there are no matching catch clauses
  13. In the catch block below, what is e?
    The name of catch block's exception parameter.
  14. Which of the following statements about the try-with-resources statement is false?
    You allocate the resource in the parentheses following the try keyword and use the resource in the try block; then you explicitly call the resource's close method at the end of the try block.
  15. Which of the following statements is false? Ch 11 No 16
    The class Throwable provides the method getStackTrace that outputs the stack trace to the standard error stream.
  16. Which of the following statements is true? Ch 11 No 8
    Like any other class, an exception class can contain fields and methods.
  17. Which of the following statements about try blocks is true? Ch 11 No 17
    The try block should contain statements that may throw an exception.
  18. Which of the following exceptions is a checked exception?
  19. The throws clause of a method header ________.
    specifies the exceptions a method throws.
  20. If the catch-or-declare requirement for a checked exception is not satisfied ________.
    the compiler will issue an error message indicating that the exception must be caught or declared
  21. A String constructor cannot be passed ________.
    int arrays
  22. Which of the following creates the string of the numbers from 1 to 1000 most efficiently?
    look on
  23. Which of the following is not a method of class String?
  24. The String method substring returns ________.
    a String
  25. Which of the following statements is true? Ch 14 No 7
    Class Matcher provides methods find, lookingAt, replaceFirst and replaceAll.Method matches (from class String, Pattern or Matcher) will return true only if the entire search object matches the regular expression.Methods find and lookingAt (from class Matcher) will return true if a portion of the search object matches the regular expression. All of these.
  26. StringBuilder objects can be used in place of String objects if ________.
    the string data is not constantthe string data size may growthe programs frequently perform string concatenation
  27. Which of the following are static Character methods?
    Character.isDigit(char c);
  28. To find the character at a certain index position within a String, use the method ________.
    charAt, with the index as an argument
  29. Which class is not a type-wrapper class?
  30. Consider the statements below:
    String a = "JAVA: ";
    String b = "How to ";
    String c = "Program";
    Which of the statements below will create the String r1 = "JAVA: How to Program"?
    String r1 = a. concat(b.concat(c));
  31. The length of a string can be determined by ________.
    the String method length()
  32. Which of the following statements is true? Ch 14 No 19
    Both "A*" and "A+" will match "AAA", but only "A*" will match an empty string.
Card Set
Programming 2 Exam 2
Programming 2 Exam 2