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) {
checkIO();
setIn0(in);
}
public static void setOut(PrintStream out) {checkIO();}
public static void exit(int status) {
Runtime.getRuntime().exit(status);
}
public static void gc() {
Runtime.getRuntime().gc();
}
In the above System class, 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.
out is a static field in a System class which is of type PrintStream ( a built in class available in java.io 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) {
this(out, false);
}
// 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 java.io package and println() is a method from the PrintStream class.
0 comments:
Post a Comment