Saturday, 6 April 2013

Most favorite Question : Logic Behind "System.out.println()"



System.out.println prints the argument passed, into the System.out which is generally stdout.

  • System – is a final class and cannot be instantiated. Therefore all its memebers (fields and methods) will be static and we understand that it is an utility class. As per javadoc, “…Among the facilities provided by the System class are standard input, standard output, and error output streams; access to externally defined properties and environment variables; a means of loading files and libraries; and a utility method for quickly copying a portion of an array…”



  • out – is a static member field of System class and is of typePrintStream. Its access specifiers are public final. This gets instantiated during startup and gets mapped with standard output console of the host. This stream is open by itself immediately after its instantiation and ready to accept data. When running a program from windows command line, it is the standard console.



  • println – println prints the argument passed to the standard console and a newline. There are multiple println methods with different arguments (overloading). Every println makes a call toprint method and adds a newline. print calls write()and the story goes on like that.

Post a Comment