System.out.println()


System.out.println()

Not only the novices but also a few Programmers do not aware of the meaning of System.out.prinltn() statement. Following is the description of each word in the statement.

What is System.out.println()?
  1. out is an object PrintStream class defined in System class. out is declared as public, static and final.
  2. println() is a method of PrintStream class.
  3. The println() method is called with out object.
  4. 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.

About "out"

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.

About "error"

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.

Do you know what is System.in?

47 thoughts on “System.out.println()”