When we want to print line in console we write System.out.println(data), what will be difference if we use PrintStream object out and use out.println(data).
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
We don’t. It is just a convenient way to get hold of the
PrintStreamobject for writing to standard output.It depends on how you obtained the
PrintStreamobject.If you originally got the
PrintStreamobject fromSystem.outorSystem.err, then there is no difference; e.g. the following have the same effect:If you created the PrintStream on a stream that opened yourself, the behaviour will be analogous, but the output will (most likely) go to a different place; e.g.
will write “hello” to the named file.
There is nothing special about
System.in/out/err. They are justpublic static finalvariables that are initialized to specific stream objects when the JVM starts. (OK, there is something slightly unusual about them … but it doesn’t manifest here.)