1Z0-829 Java I/O API and Securing Applications Practice Question
A financial services company runs a Java 17 application on a server with 8 GB RAM. The application reads daily transaction files in CSV format (each file is about 500 MB). It processes each line, validates it against a SQL database, and writes results to an output file. Recently, after processing about 60% of a file, the application crashes with an OutOfMemoryError: Java heap space. The heap size is set to 2 GB. The code uses Files.readAllLines() to load the entire file into a List<String>, then iterates. The team is evaluating solutions to avoid memory issues. Which approach is the best course of action?
⚠ Common exam trap
It's easy for candidates to choose to increase heap size (Option A) as a quick fix, missing the fundamental design flaw of loading the entire file into memory, which is a classic Java anti-pattern tested in the 1Z0-829 exam.
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
✓
Replace Files.readAllLines() with Files.lines() and process the stream line by line.
Files.readAllLines() loads the entire 500 MB CSV file into memory as a List<String>, which causes the OutOfMemoryError when combined with other heap usage. Replacing it with Files.lines() returns a Stream<String> that reads lines lazily, processing each line one at a time without holding the entire file in memory. This directly solves the heap space issue without requiring additional hardware or manual file splitting.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Increase the JVM heap size to 4 GB.
Why it's wrong here
Does not solve the root cause; may still OOM with larger files.
- ✗
Enable class data sharing to reduce memory footprint.
Why it's wrong here
CDS reduces startup memory, not heap usage for data.
- ✗
Split the file into 100 MB chunks and process each chunk sequentially.
Why it's wrong here
Still uses readAllLines on chunks; OOM possible for 500 MB if not streamed.
- ✓
Replace Files.readAllLines() with Files.lines() and process the stream line by line.
Why this is correct
Streams lines lazily, fits in memory regardless of file size.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 1Z0-829 question from scratch — 513 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. 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.