1Z0-829 Java I/O API and Securing Applications Practice Question
A method receives an InputStream and needs to compute its MD5 hash while reading the data. Which approach is most efficient?
⚠ Common exam trap
A common mix-up: candidates assume reading all bytes into memory first (Option B) is simpler or more straightforward, overlooking the memory and performance implications for large streams, and fail to recognize that `DigestInputStream` is the standard, efficient solution in the Java I/O API.
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 DigestInputStream wrapping the original stream, then read the stream
`DigestInputStream` is a built-in Java class that computes a message digest (e.g., MD5) on the fly as data is read from the underlying stream. This avoids buffering the entire stream into memory, making it both memory-efficient and CPU-efficient for large or streaming data sources.
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 DigestInputStream wrapping the original stream, then read the stream
Why this is correct
DigestInputStream computes the hash as data is read, requiring no additional memory.
- ✗
Read all bytes into a byte array, then compute hash using MessageDigest
Why it's wrong here
Loading entire stream into memory is inefficient for large streams.
- ✗
Use a custom filter that hashes bytes during read
Why it's wrong here
Custom implementation is unnecessary when DigestInputStream is available.
- ✗
Use Scanner to read tokens and update hash
Why it's wrong here
Scanner is for parsing, not for hashing streams.
Go deeper
Related to this question
About these practice questions
One of 513 original 1Z0-829 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
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.