nerdexam
Oracle

1Z0-819 · Question #63

public class Main { public static void main(String[] args) { try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { String input = br.readLine(); System.out.print("Input…

The correct answer is D. System.in is the standard input stream. The stream is already open. System.in is a static field of the java.lang.System class representing the standard input stream - it is always open from JVM startup, which is why wrapping it in a BufferedReader works immediately without any explicit open call, as the code demonstrates. Why the distractors…

Java I/O API

Question

public class Main { public static void main(String[] args) { try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { String input = br.readLine(); System.out.print("Input string was: " + input); } catch (IOException e) { e.printStackTrace(); } } } Which is true?

Options

  • ASystem.out is the standard output stream. The stream is open only when System.out is called
  • BSystem.in cannot reassign the other stream.
  • CSystem.err is printstream and java.OutputStream by default.
  • DSystem.in is the standard input stream. The stream is already open.

How the community answered

(36 responses)
  • A
    8% (3)
  • B
    14% (5)
  • C
    6% (2)
  • D
    72% (26)

Explanation

System.in is a static field of the java.lang.System class representing the standard input stream - it is always open from JVM startup, which is why wrapping it in a BufferedReader works immediately without any explicit open call, as the code demonstrates.

Why the distractors are wrong:

  • A is false because System.out is always open too - it's not opened on-demand when called; it's a pre-opened PrintStream available from JVM startup.
  • B is false because System.in can be reassigned using System.setIn(InputStream), which replaces the standard input with another stream.
  • C is partially misleading - System.err is indeed a PrintStream, but PrintStream extends FilterOutputStream which extends OutputStream, not java.io.OutputStream directly as a separate interface; more importantly, the phrasing "by default" is vague and the statement conflates inheritance with instantiation in a way that makes it incorrect as written.

Memory tip: Think of the three standard streams (System.in, System.out, System.err) as always-on pipes - they're wired up before your main method runs and stay open for the JVM's lifetime, just like stdin/stdout/stderr in any Unix process.

Topics

#System.in#Stream lifecycle#Standard I/O#Try-with-resources

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice