Monday, December 29, 2014

Explain about System.out.println()


System is a final class available in java.lang package. It is a system related class and most of times make native calls.

Structure of System class:

public final class System {

public final static InputStream in = null;
public final static PrintStream out = null;
public final static PrintStream err = null;

private System() {


   public static void setIn(InputStream in) {

  public static void setOut(PrintStream out) {

   public static void exit(int status) {

   public static void gc() {

In the above System class, both err and out are instances of PrintStream class ( System class has setters for all the three mentioned above but no getters. InputStream is again from package.

out is a static field in a System class which is of type PrintStream ( a built in class available in package, which contains several methods to print the different data values). In order to acess any static methods or static members we are using class name. So System.out

Structure of PrintStream:

public class PrintStream extends FilterOutputStream implements Appendable, Closeable {
  public PrntStream(OutputStream out) {    

    // Different arguments with print() and println() methods
      public void print() {
 public void println() {

    // printf() and format() methods


println - is a method of PrintStream class. println method prints the arguments passed to standard console and a new line. There are several print() and println() methods with different arguments. Every println() method makes a call to print() method and adds newline.

System is class in java.lang package and out is the instance of PrintStream class from package and println() is a method from the PrintStream class.