Skip to content
Sharp

I/O interview questions

Streams vs readers, buffering, NIO.2, serialization.

4 questions with answers and explanations · 2 flashcards

Key ideas

  • Byte streams (InputStream/OutputStream) vs character streams (Reader/Writer, which handle charsets).
  • Wrap with BufferedReader/BufferedWriter to avoid one system call per character.
  • NIO.2: Path and Files (Files.readAllLines, Files.lines, Files.writeString).
  • Serialization needs Serializable; transient and static fields aren't serialized. Never deserialize untrusted data.

Questions

  1. Which class should you wrap around a FileReader to read text efficiently line by line?Multiple choiceEasy
  2. Which java.nio.file.Files method reads all lines of a small text file into a List<String>? (method name)Fill in the blankMedium
  3. Which statements about Java serialization are true? Select all that apply.Select all that applyMedium
  4. What does new File("data.txt") do if data.txt doesn't exist?Multiple choiceMedium