Tuesday, June 12, 2012

System.out.println(), What is it?

System is a class in java.lang package. It is a system related class and most of times make native calls. As far as out is concerned. System class declares it something like this:
  public final static InputStream in = null; 
  public final static PrintStream out = null; 
  public final static PrintStream err = null; 
As shown above both err and out are instances of PrintStream class (java.io.PrintStream). System class has setters for all the three mentioned above but no getters. InputStream is again from java.io package. Setters are written something like as shown:
  public static void setOut(PrintStream out) { 
    checkIO(); 
    setOut0(out); 
 }
Summarizing above, System is class in java.lang package and out is the instance of PrintStream class from java.io package and println() is a method from the PrintStream class obviously.

2 comments:

  1. Nice explanation Dharmvir Singh!

    I too explained the same in one of forums. Please do comment on that please?

    ReplyDelete