Not only the novices but also many programmers do not aware of the meaning of System.out.prinltn() statement. Following is the description of each word in the statement.
- out is an object PrintStream class defined in System class. out is declared as public, static and final.
- println() is a method of PrintStream class.
- The println() method is called with out object.
- The out object is called with System class.
To say simple, println() is a method of PrintStream class. out is an object of PrintStream class defined in System class.
So, we are calling println() with out object and out object with System class.
We know out is an object of PrintStream class defined in System class. Internally the out object is connected to the "standard output stream" of underlying operating system. So, any data given to out object goes to the OS out stream and prints at the DOS prompt.
We know earlier, the object out of PrintSteam is connected to the standard output stream of the underlying operating system. Similarly, there exist another object err of the same PrintStream that is connected to the standard error stream of the underlying operating system. The data given to err also goes to the DOS prompt.
The following two statements do the same job of writing to the destination DOS prompt.
System.out.println("Hello"); // observe, out
System.err.println("Hello"); // observe, err
The first one is preferred to display any messages at DOS prompt, useful to the client, by the programmer. The second one is best suitable to display error messages at DOS prompt as in a catch block etc.
A similar program exists on PrintWriter that prints data at DOS prompt.