Engineering Interviews · interview question
How would you explain a severe bug in this code regarding resource management in an interview?
Multiple choiceHardchapter-20-curatedpremiumengineering-interviewscode-review-spotting-bugs
public void readFile(String fileName) {
InputStream input = new FileInputStream(fileName);
// process the input
}Answer and explanation
Correct answer
C. InputStream is not closed, leading to resource leaks
Why
The InputStream should be closed after use to free up system resources. Failing to do so can lead to resource leaks, eventually causing the application to run out of file handles.
Test yourself on Engineering Interviews
A free test with instant, explained results. No account needed.
More Engineering Interviews questions
- In the context of JVM memory architecture, what is the primary role of the 'stack'?
- Why is it important to first outline a high-level design before diving into coding during a system design interview?
- During a live coding interview, why is it important to verbalize your thought process?
- What does the 'Result' component in the STAR framework mainly aim to achieve?
- Why is it crucial to agree on an algorithm before writing code in a live coding interview?
- In a code review, which type of bug is most critical to address immediately?