-2

In the documentation code of java "out" is an object of PrintStream class which is initialized in the System class of package lang.This object "out" is initialized to null.So why does'nt the code throws a null pointer exception whenever the line

System.out.println(...); is used

2 Answers2

3

It is the field declaration.

Look at the initializeSystemClass() static method :

setOut0(newPrintStream(fdOut, props.getProperty("sun.stdout.encoding")))

The out is well initialized at a time by the VM.

The method is commented with this :

/**
 * Initialize the system class.  Called after thread initialization.
 */
davidxxx
  • 125,838
  • 23
  • 214
  • 215
-1

The .out variable is a static variable of System. It's the default outputStream and not null.

Java Documentation: This stream is already open and ready to accept output data.

Phillip K
  • 7
  • 3