← All OCP Flashcard Decks

OCP Java IO and NIO Flashcards

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

Read the first 6 OCP Java IO and NIO flashcards as text
  1. Which interface must a Java class implement to allow its instances to be serialized to a byte stream?

    Answer: java.io.Serializable

    java.io.Serializable is a marker interface (no methods) that signals the JVM that a class's objects may be serialized.

  2. What is the purpose of the serialVersionUID field in a Java serializable class?

    Answer: To provide a version identifier for compatibility verification during deserialization

    serialVersionUID is used by the deserialization mechanism to verify that the loaded class version matches the serialized object's class version.

  3. Which Java keyword prevents a specific field from being included in object serialization?

    Answer: transient

    Fields marked transient are skipped during serialization and will have their default values (null, 0, false) after deserialization.

  4. Which NIO class provides a non-blocking, bidirectional channel for TCP network communication?

    Answer: SocketChannel

    SocketChannel is the NIO channel for TCP connections, supporting non-blocking I/O for both reading and writing network data.

  5. What role does java.nio.ByteBuffer serve when reading data from or writing data to an NIO channel?

    Answer: It acts as the data container that channels read into and write from

    ByteBuffer is the mandatory data container for NIO channel operations — all channel read() and write() calls operate on ByteBuffer instances.

  6. What happens at runtime when ObjectOutputStream.writeObject() is called with an object whose class does not implement Serializable?

    Answer: A NotSerializableException is thrown at runtime

    If an object's class does not implement Serializable, writeObject() throws NotSerializableException at runtime when it attempts to serialize that object.