System.out.println()?

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.

  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?

Java IO at a Glance

45 Responses

  1. Ram July 17, 2014 / 10:25 pm

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

      • Roja September 19, 2014 / 9:14 pm

        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. Megha July 17, 2014 / 12:52 pm

    hii sir..
    why we use 3 dots after String like in public static void main(String… a)?
    what does it mean??

  3. RK March 20, 2014 / 6:36 am

    its a good platform for everyone even better than books

  4. seo December 18, 2013 / 8:39 pm

    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.

  5. Pawan September 15, 2013 / 5:30 pm

    i’m confused in stringargs[]……tell me more about it why we mention it in java program?

  6. barun August 1, 2013 / 9:54 pm

    What is the meaning of ArrayListcities=new ArrayList();

  7. arjun February 20, 2013 / 6:25 pm

    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

  8. himanshu January 25, 2013 / 11:05 pm

    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 ……..

    • S. Nageswara Rao, Corporate Trainer February 3, 2013 / 6:43 pm

      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.

    • S. Nageswara Rao, Corporate Trainer February 17, 2013 / 5:28 am

      To understand the internals of Java, the knowledge of microprocessor design is not essential. The .exe file of C/C++ generate binary code which is OS dependent. For this reason, on which OS the .exe file is generated, on the same OS it must be executed.

  9. saidulu kakunuri October 13, 2012 / 5:09 pm

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

    thanking you sir…

  10. M.pavankumarreddy August 14, 2012 / 4:40 pm

    Sir can u plz give me the code for System.out.println() with their classes?

  11. Santosh Kumar Pandey July 25, 2012 / 1:42 am

    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

  12. v.s. July 5, 2012 / 12:34 am

    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

    • S. Nageswara Rao, Corporate Trainer July 5, 2012 / 8:37 pm

      Correct your code as follows:
      import java.io.*;
      class b
      {
      public static void main(String… a)
      {
      PrintStream c=new PrintStream(System.out);
      c.println(“dfsaf”);
      }
      }

      • M.pavankumarreddy August 14, 2012 / 4:45 pm

        Sir why u have mentioned System.out in the constructor of PrintStream class what is this meaning??

        • S. Nageswara Rao, Corporate Trainer August 15, 2012 / 5:01 am

          All streams are carriers of data. PrintStream carries to the destination. Which destination, where it is to be mentioned? It is mentioned in the constructor of PrintStream. System.out is connected to the OS stream that carries to the dos prompt.

      • kalaiselvan December 23, 2012 / 10:40 am

        hlo sir Pls explain

        What is difference between String and string in java ? where it’s using this String and string ….

  13. v.s. July 5, 2012 / 12:15 am

    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

  14. Krishna June 26, 2012 / 11:57 am

    Sir could you provide the mystery behaind System.out.println()

  15. manoj June 15, 2012 / 10:54 am

    hi sir..,why “+” operator is present is System.out.printl(“sum” + sum);

  16. uday March 17, 2012 / 8:33 pm

    hi sir,
    System class is defined in which package?

  17. Pradeep Patel February 25, 2012 / 2:22 pm

    Hello Sir…
    I didn’t get the actual meaning of System.out.println()….
    Please help me…

    With Regards..

    • S. Nageswara Rao, Corporate Trainer February 27, 2012 / 12:35 pm

      System.out is internally connected to the output mechanism of the underlying operating system. To println() parameter, we pass data that is to be printed at the command prompt. Remaining things are explained in the site.

  18. uday November 24, 2011 / 1:11 pm

    hi sir,
    can I write a main() method inside an abstract class?

Leave a Reply

Your email address will not be published. Required fields are marked *