← All SCJP Flashcard Decks

Exception Handling and Java I/O Flashcards

6 cards from real SCJP practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 6 Exception Handling and Java I/O flashcards as text
  1. Which of the following is NOT a valid exception handling structure in Java?

    Answer: catch-finally (without try)

    A `catch` or `finally` block cannot exist without a preceding `try` block — Java requires `try` to begin an exception handling structure.

  2. What is the difference between `Error` and `Exception` in Java?

    Answer: Errors represent serious system-level problems not meant to be caught; Exceptions are application-level issues

    `Error` (e.g., `OutOfMemoryError`) signals serious JVM-level problems that programs typically cannot recover from, while `Exception` covers application-level issues.

  3. Which Java I/O class should be used to write primitive data types (int, double, boolean) to a stream?

    Answer: DataOutputStream

    `DataOutputStream` provides methods like `writeInt()`, `writeDouble()`, and `writeBoolean()` for writing primitive data types in a portable binary format.

  4. What is the try-with-resources statement used for in Java 7+?

    Answer: To automatically close resources that implement AutoCloseable

    Try-with-resources automatically calls `close()` on any `AutoCloseable` resource declared in the try header when the block exits.

  5. In Java, can a single `catch` block catch multiple exception types?

    Answer: Yes, using a pipe (|) separator since Java 7 (multi-catch)

    Java 7 introduced the multi-catch feature: `catch (IOException | SQLException e)` catches both exception types in one block.

  6. Which stream class in Java allows reading and writing to the same file simultaneously?

    Answer: RandomAccessFile

    `RandomAccessFile` supports both reading and writing to a file and allows the file pointer to be moved to any position.

How this page was made: written with AI tools and published by Nathan Beja, founder of Practice Test Geeks, who is responsible for its content. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Not reviewed by a subject-matter expert. Editorial policy