aspose file tools*
The moose likes Beginning Java and the fly likes Java Println Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Println" Watch "Java Println" New topic

Java Println

Sankar Vaiyapuri

Joined: Oct 10, 2011
Posts: 3

In System.out.println() the System is a Class and out is a static instance of PrintStream in System class. println() is a method in PrintStream class. So the method println() is called using System.out. But the out instance is static,final and it is initialized to null in System class. Then how it calls println() method?
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 39409
What makes you think it is initialised to null?
Rob Spoor

Joined: Oct 27, 2005
Posts: 19720

The Java source code from From the source of java.lang.System:
However, elsewhere we see this:
This method in turn is called when the class is loaded:
And that's how in the end System.out is initially set.

Note that although, System.out and System.err are final, the JVM still is able to change them through System.setIn, System.setOut and System.setErr. That's because it uses native code to do so, and the JVM can do a lot through native code that we can't.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Java Println