NIO.2 — Non-Blocking I/O — Concept Check
Questions on NIO.2 — Non-Blocking I/O. NIO.2 provides asynchronous file I/O, file system watching, and high-performance channel-based I/O for demanding applications.
Questions in this quiz
8 questions on NIO.2 — Non-Blocking I/O — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer is using NIO.2 to watch a directory for changes. They notice that some file modifications are not being detected. What could be the issue?
- AThe WatchService is not registered for ENTRY_MODIFY events.
- BThe directory is being accessed by another process.
- CThe WatchService only detects create and delete events.
- DThe WatchService is not compatible with symbolic links.
2.You are implementing a high-throughput server using AsynchronousFileChannel. What is a key advantage of using asynchronous I/O in this context?
- AIt reduces memory usage by avoiding buffer allocation.
- BIt prevents thread blocking, allowing more concurrent operations.
- CIt guarantees faster disk access speeds.
- DIt simplifies code by removing the need for callbacks.
3.A developer uses Path.of() to create a path and calls normalize(). What is the expected result?
- AIt changes the path to use the default filesystem.
- BIt resolves symbolic links in the path.
- CIt converts the path to an absolute path.
- DIt removes redundant elements like '.' and '..'.
4.A developer is using AsynchronousSocketChannel for a chat application. They notice that messages are delayed. What could be causing this?
- AThe CompletionHandler is not implemented correctly.
- BThe channel is blocking, preventing timely reads.
- CThe buffer size is too large, causing delays.
- DThe network latency is high, impacting message delivery.
5.A team is using WatchService to monitor configuration files. They find that changes are sometimes missed. What might be the cause?
- AThe files are not being closed after modification.
- BThe WatchKey is not reset after processing events.
- CThe directory is too large for WatchService to handle.
- DThe WatchService is not running in a separate thread.
6.What is the role of Path in NIO.2?
- ATo manage file permissions and attributes.
- BTo handle network connections in a non-blocking way.
- CTo replace java.io.File with an immutable path representation.
- DTo provide a mutable file path representation.
7.A developer uses Files.size() on a Path object but gets an unexpected result. What might be the reason?
- AThe file is being accessed by another process, causing an error.
- BThe file is a symbolic link, and size() returns the link size.
- CThe file is too large for the size() method to handle.
- DThe file is not readable, so size() returns zero.
8.A developer uses AsynchronousFileChannel to read a large file but notices the read operation is slow. What could be the reason?
- AThe buffer size is too small, requiring many reads.
- BThe file is fragmented on disk, slowing access.
- CAsynchronousFileChannel is inherently slower than synchronous I/O.
- DThe file is not opened with the correct permissions.