System.out.println() is used mostly to print messages to the console. However very few of us are actually aware of its working mechanism.
- System is a class defined in the java.lang package.
- out is an instance of PrintStream , which is a public and static member of the class System.
- As all instances of PrintStream class have a public method println(), hence we can invoke the same on out as well. We can assume System.out represents the standard Output Stream .
One interesting fact related to the above topic is, we can use System.out.println() to print messages to other sources too (and not just console) . However before doing so , we must reassign the standard output by using the following method of System class:
PrintStream can be used for character output to a text file. Below program creates the file A.txt and writes to the file using System.out.println(
In very similar fashion we can use System.out.println() to write to a Socket’s OutputStream as well.
This article is contributed by Ashutosh Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Java IO : Input-output in Java with Examples
- Output of Java Program | Set 6
- Output of Java Program | Set 9
- Output of Java Program | Set 7
- Output of Java Programs | Set 12
- Output of Java Program | Set 8
- Output of Java Program | Set 4
- Formatted output in Java
- Output of Java program | Set 5
- Output of Java Program | Set 3
- Output of Java Program | Set 11
- Output of Java Program | Set 1
- Output of Java Program | Set 2
- Output of Java Programs | Set 54 (Vectors)
- Output of Java programs | Set 13 (Collections)
- Output of Java Programs | Set 14 (Constructors)
- Java Tricky Output Questions
- Java.io.File Class in Java
- Output of Java programs | Autoboxing and Unboxing
- Output of Java programs | Set 10 (Garbage Collection)