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()”

  1. Generally we call a method with object. Same is done as we write – out.println() . But why we mention the class name System?

      1. Sir,
        println() method is defined in the printstream class.To call println() method we create an object called out.here we are defining out object in printstream class itself but you said out object defined in the System class.I’m confused with PrintStream and System class.could you please explain in detail?

  2. hi!,I love your writing so so much! share we keep up a correspondence extra approximately your article on AOL?
    I need a specialist on this house to solve my problem. Maybe that’s
    you! Taking a look forward to look you.

  3. best site to learn core java.

    sir can u send me the link of call by value and call by reference, bcz i didn’t find till now

  4. sir, your site is very helpful for clearing doubts …
    could you tell me that what are the factors or causes that makes c/c++ platform dependent ….i have little knowledge of microprocessor and assembly language and i guess that answer will be somewhere related with these two things ……..

    1. To understand this, you need not know about MP design. C/C++ compiler generates executable binary code whose order of 0 and 1s is different for different platforms. For this reason, the pattern of binary code generated one OS will not work on other. That is binary code is platform dependent.

  5. saidulu kakunuri

    hellow sir i like your website …because the best stuff is given by you about system.out.println()…

    thanking you sir…

  6. Santosh Kumar Pandey

    sir your site is very useful, with the help of the contents on it i clear my several doubts, sir please provide some contents on advance java & various frameworks also.
    thanks sir

  7. sir if i do this

    class b
    {
    public static void main(String… a)
    {
    PrintStream c=new PrintStream();
    c.println(“dfsaf”);
    }
    }

    why this showing error i hav just made object of PrintStream class and tried to access thier method

  8. sir if i do this

    class b
    {
    public static void main(String… a)
    {
    PrintStream c=new PrintStream();
    c.println(“dfsaf”);
    }
    }

    why this showing error i hav just made object of PrintStream class and tried to access thier method

      1. Hi sir,
        could you please provide some material on Advanced java like core java. And your site is very useful to java learners.

Leave a Comment

Your email address will not be published.