Overview
Domain 9 has three objectives. The first is reading and writing console and file data with I/O streams: InputStream and OutputStream for bytes, Reader and Writer for characters, buffered and print wrappers, and the Console class. The second is serializing and deserializing objects with ObjectOutputStream and ObjectInputStream. The third, usually the largest, is the NIO.2 API: constructing Path objects, navigating with resolve, relativize and normalize, and using Files to create, copy, move, delete, read, write and inspect files and directories.
Questions mix output prediction for Path methods with behaviour questions such as which exception a Files call throws, what a deserialized object contains, or why System.console() returned null.
How it's tested
Expect short NIO.2 snippets where you predict the printed Path, file-operation sequences where you choose the exception or final state, and serialization classes where you predict field values after a round trip. Read every path string literally, including leading slashes, dots and trailing names.
-
Path arithmetic
resolve, relativize, normalize, subpath or getName are applied to path strings, and you choose the printed result or an exception.
-
Files behaviour
A sequence of createDirectory, copy, move or delete calls runs, and you decide whether it succeeds or which exception it throws.
-
Serialization round trip
An object with transient, static and inherited fields is written and read back, and you predict each field's value.
Code calls Path.of("/app/logs").resolve("/tmp/out.txt"). Many expect /app/logs/tmp/out.txt. When the argument to resolve is an absolute path, resolve simply returns the argument, so the result is /tmp/out.txt. Had the argument been the relative tmp/out.txt, the paths would be joined to give /app/logs/tmp/out.txt. This rule matters when configuration values may hold either kind of path, because an absolute setting silently replaces the base directory instead of being nested inside it.
Objectives 3
Official objectives from the Oracle outline, in outline order.
9.1 Read and write console and file data using I/O Streams.Byte and character streams, buffering, PrintWriter and the Console class.
- What it means
- java.io uses byte streams, based on InputStream and OutputStream, for binary data, and character streams, based on Reader and Writer, for text. Wrapper classes such as BufferedReader, BufferedWriter and PrintWriter add buffering and convenience methods. The Console class reads user input and passwords from an interactive terminal.
- What to understand
- Low-level streams such as FileInputStream and FileReader connect to a source, and high-level streams wrap another stream. BufferedReader.readLine returns null at end of input, and InputStream.read returns -1. FileWriter and FileOutputStream overwrite by default and append when given true as a second argument. PrintWriter methods do not throw IOException; check errors with checkError. Always close streams, ideally with try-with-resources, and closing the outer wrapper closes the inner stream. System.console() can return null when no interactive console is attached, for example inside an IDE or when output is redirected. Console.readPassword returns a char[] so the password can be cleared from memory, and Console.readLine and format support formatted prompts.
- How it shows up
- Expect loops reading until null or -1, append versus overwrite questions, and Console null checks.
- Common confusion
- Thinking readLine returns an empty string at end of file, or that System.console() always returns an object.
9.2 Serialize and de-serialize Java objects.Serializable, ObjectOutputStream, ObjectInputStream, transient fields and constructor behaviour.
- What it means
- Serialization converts an object graph into bytes with ObjectOutputStream.writeObject, and deserialization rebuilds it with ObjectInputStream.readObject. A class opts in by implementing the marker interface Serializable, and every object reachable through non-transient fields must also be serializable.
- What to understand
- transient fields are skipped and come back with default values such as null, 0 or false, and static fields belong to the class, so they are not stored with the object. During deserialization, constructors and instance initializers of serializable classes do not run; Java calls the no-argument constructor of the first non-serializable superclass, which must exist and be accessible. Records are an exception: they are rebuilt through their canonical constructor. A field referencing a non-serializable object causes NotSerializableException when writing. serialVersionUID identifies the class version, and a mismatch causes InvalidClassException. readObject returns Object, so the caller casts it, and reading past the last object throws EOFException.
- How it shows up
- Expect classes with transient fields, inherited state from a non-serializable parent, and initializers that do not run on read.
- Common confusion
- Expecting constructors to run during deserialization, or transient fields to keep the values they had when written.
9.3 Construct, traverse, create, read, and write Path objects and their properties using the java.nio.file API.Path creation and navigation, and Files methods for files, directories and attributes.
- What it means
- A Path represents a location in a file system, created with Path.of or Paths.get. Path methods inspect and combine paths without accessing the disk. The Files class performs real operations: checking existence, creating, copying, moving, deleting, reading, writing, listing, walking and reading attributes.
- What to understand
- getFileName, getParent, getRoot, getNameCount, getName and subpath read path parts; getName(0) is the first element after the root, and subpath's end index is exclusive. resolve joins paths unless the argument is absolute, relativize builds a path from one location to another and throws IllegalArgumentException if one is absolute and the other relative, normalize removes redundant . and .. elements, and toRealPath checks the file exists and resolves links. Files.createDirectory fails if the parent is missing or the target exists, while createDirectories builds the whole chain. copy and move throw FileAlreadyExistsException unless REPLACE_EXISTING is given, delete throws NoSuchFileException where deleteIfExists returns false. readAllLines loads a List, lines and walk return lazy streams that should be closed, list goes one level deep, and readAttributes returns BasicFileAttributes.
- How it shows up
- Expect printed results of resolve, relativize and normalize, and exceptions from createDirectory, copy and delete.
- Common confusion
- Believing Path methods check that files exist, or that resolve with an absolute argument appends it.
High-yield concepts
The terms, rules and formulas this domain turns into questions most often.
-
Byte versus character streams
InputStream and OutputStream versus Reader and Writer.
- Remember
- Use Reader and Writer for text.
- Tested as
- Class selection questions.
- Trap
- Using byte streams to read lines of text.
-
End of input
Signals that no more data remains.
- Remember
- readLine returns null; read returns -1.
- Tested as
- Loop termination questions.
- Trap
- Checking for an empty string.
-
System.console()
Access to the interactive console.
- Remember
- May return null; readPassword returns char[].
- Tested as
- Console questions.
- Trap
- Assuming a Console is always available.
-
transient
Field modifier that excludes data from serialization.
- Remember
- Deserialized value is the type default.
- Tested as
- Round-trip output questions.
- Trap
- Expecting the original value back.
-
Deserialization constructors
Rules for which constructors run.
- Remember
- Only the first non-serializable superclass constructor runs.
- Tested as
- Field value questions.
- Trap
- Expecting the class's own constructor output.
-
resolve
Joins one path to another.
- Remember
- An absolute argument is returned unchanged.
- Tested as
- Path output questions.
- Trap
- Concatenating absolute paths.
-
relativize
Builds a path from this path to another.
- Remember
- Both must be absolute or both relative.
- Tested as
- Path output and exception questions.
- Trap
- Mixing absolute and relative paths.
-
normalize
Removes . and resolvable .. elements.
- Remember
- Purely syntactic; ignores the file system.
- Tested as
- Path output questions.
- Trap
- Expecting it to resolve symbolic links.
-
createDirectory versus createDirectories
Single directory versus full chain.
- Remember
- createDirectory fails when parents are missing.
- Tested as
- Exception questions.
- Trap
- Expecting createDirectory to build parents.
-
Files.lines
Lazy stream of lines from a file.
- Remember
- Close it, ideally in try-with-resources.
- Tested as
- Resource questions.
- Trap
- Treating it like readAllLines.
-
REPLACE_EXISTING
Copy and move option to overwrite targets.
- Remember
- Without it, existing targets cause FileAlreadyExistsException.
- Tested as
- Files.copy questions.
- Trap
- Assuming copy overwrites by default.
Side by side
Concepts candidates mix up, compared on the point that decides the answer.
Reading file text
| Concept | Meaning | Key difference | Common trap |
|---|---|---|---|
| BufferedReader.readLine | Line-by-line classic I/O | Returns null at end | Forgetting to close the reader |
| Files.readAllLines | Loads every line into a List | Eager; simple for small files | Using it on very large files |
| Files.lines | Lazy Stream of lines | Must be closed; integrates with streams | Leaving it open after use |
| Files.readString | Whole file as one String | Convenient for small text files | Expecting a list of lines |
Path operations
| Concept | Meaning | Key difference | Common trap |
|---|---|---|---|
| resolve | Combine a base path with another | Absolute argument wins | Expecting simple concatenation |
| relativize | Path from one location to another | Needs matching path types | Mixing absolute and relative |
| normalize | Remove redundant elements | No disk access | Expecting existence checks |
| toRealPath | Absolute, link-resolved real path | Accesses the disk; file must exist | Calling it on a missing file |
Exam traps
Each trap is an answer that looks right. Learn the clue that should change your mind.
-
Constructor runs on read
- What candidates pick
- Picks output that includes a serializable class's constructor message after readObject.
- Why it looks right
- Objects are normally built by constructors.
- Why it's wrong
- Deserialization restores serializable classes without calling their constructors; only the first non-serializable superclass constructor runs.
Clue to watch for Print statements inside constructors of a Serializable class.
-
Path methods check the disk
- What candidates pick
- Expects normalize or resolve to throw for a missing file.
- Why it looks right
- File-related methods often throw IOException.
- Why it's wrong
- Path methods manipulate names only; toRealPath and Files methods are the ones that access the file system.
Clue to watch for Path code with no Files calls and a nonexistent location.
-
Mixed relativize
- What candidates pick
- Computes a result for an absolute and a relative path.
- Why it looks right
- The method seems able to work anything out.
- Why it's wrong
- relativize requires both paths to be the same kind and otherwise throws IllegalArgumentException.
Clue to watch for One path string starting with a slash and one without.
-
Copy overwrites
- What candidates pick
- Assumes Files.copy replaces an existing target.
- Why it looks right
- Many command-line tools overwrite by default.
- Why it's wrong
- Without StandardCopyOption.REPLACE_EXISTING, copy throws FileAlreadyExistsException when the target exists.
Clue to watch for A copy call to a target created earlier in the code.
-
Console always present
- What candidates pick
- Calls methods on System.console() without a null check and expects output.
- Why it looks right
- System.out always exists.
- Why it's wrong
- System.console() returns null when there is no interactive terminal, causing a NullPointerException.
Clue to watch for Code run from an IDE or with redirected input.
Answer framework
Use these steps to work through I/O and file questions methodically.
- Decide whether the code uses java.io streams, Console, serialization, Path methods or Files methods, since only some of them touch the disk.
- For Path questions, write out each path element, then apply normalize, resolve, relativize or subpath literally, watching absolute versus relative forms.
- For Files calls, ask whether the target and its parents exist, and whether options such as REPLACE_EXISTING change the outcome or exception.
- For classic streams, check end-of-input handling, append flags, buffering and whether try-with-resources closes the outer and inner streams.
- For serialization, list each field as serialized, transient or static, and identify which superclass constructor runs during deserialization.
Practice question
Want more like this? The 1Z0-830 practice test has questions for every domain.
Checklist
0 of 11
Tick each one you can do without notes. Your ticks stay in this browser.
Study strategy
Work through this section in three practical sessions. In the first, write programs that read and write text with BufferedReader and PrintWriter, then copy a binary file with FileInputStream and FileOutputStream. Test append mode, print the value returned at end of input, and run a Console program from a terminal and from your IDE to see when System.console() returns null.
In the second session, build a small class hierarchy with a non-serializable parent, a serializable child, a transient field, a static field and constructors that print. Serialize an object, change the static field, deserialize it, and explain every printed value.
In the third session, focus on NIO.2. Create a table of path strings and predict the output of getName, subpath, normalize, resolve and relativize before running them. Then use Files to create nested directories, copy with and without REPLACE_EXISTING, delete a non-empty directory and walk a tree. Record each exception you see, since the exam often asks for exactly those.
FAQ
How much of 1Z0-830 is Domain 9, Using Java I/O API?
Oracle does not publish a weight for the I/O section. It has three objectives, and we plan for about four of the 50 questions.
Is Path.of the same as Paths.get?
Yes. Both create a Path from strings. Path.of was added in Java 11 and is the form you will see most in current code.
Does normalize check whether the file exists?
No. normalize only rewrites the path text. Use Files.exists or toRealPath when you need to involve the actual file system.
Are records serialized differently?
Yes. A serializable record is reconstructed through its canonical constructor, so any validation in that constructor runs during deserialization.
Why does readPassword return a char array?
A char array can be overwritten after use, while a String stays in memory until garbage collected, so the array limits how long the password lingers.
Do I need to know file attribute views in detail?
Know Files.size, getLastModifiedTime, isDirectory, isRegularFile and readAttributes with BasicFileAttributes. Platform-specific views are unlikely to matter.
Test your Domain 9 knowledge
You have reviewed byte and character streams, Console, serialization, and Path and Files operations. Test whether you can predict path results and file-operation exceptions accurately.
Keep going
- Training Training Built on your Weak areas
- Practice test Questions by domain, with explanations
- Mock exam Full length, timed like the real exam
- Readiness test Find your weakest domain in minutes
- Cheat sheet Key terms and formulas on one page
- Ask the 1Z0-830 AI tutor Get any concept explained your way