Courseiva
Java I/O API and Securing ApplicationshardMultiple ChoiceObjective-mapped

1Z0-829 Java I/O API and Securing Applications Practice Question

An application must read a configuration file that is updated frequently by another process. The developer wants to avoid stale data and minimize I/O operations. Which approach is best?

⚠ Common exam trap

Test-takers frequently choose option C (polling with lastModified) because it seems simple and avoids continuous reads, but they overlook that polling still wastes resources and may miss updates, whereas WatchService is the true event-driven solution that minimizes I/O and avoids stale data.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Use java.nio.file.WatchService to monitor the file for modifications and reload when notified

Java.nio.file.WatchService provides an event-driven mechanism to monitor file system changes, such as modifications to a configuration file. This approach avoids stale data by reloading the file only when a change is detected, and it minimizes I/O operations by eliminating the need for polling or repeated reads. The WatchService uses the underlying OS file system events (e.g., inotify on Linux, ReadDirectoryChanges on Windows) for efficient notification.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Use java.nio.file.WatchService to monitor the file for modifications and reload when notified

    Why this is correct

    WatchService provides asynchronous notifications, reducing unnecessary reads and ensuring freshness.

  • Read the file from disk every time it is accessed using Files.newInputStream()

    Why it's wrong here

    Reading on every access causes excessive I/O, especially if the file is accessed frequently.

  • Periodically check the file's lastModified timestamp using File.lastModified() and reload if changed

    Why it's wrong here

    Polling still involves frequent I/O and timestamps may have limited granularity.

  • Read the file once at startup and cache the content in memory

    Why it's wrong here

    This ignores updates, leading to stale data.

About these practice questions

This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.