System.out.println in java


In this post, we will see about System.out.println in java and how it works.

Did you use system.out.println before? I think this is first statement every java developer compiles. It is generally called by the acronym “SOP”.

What is System.out.println?

System.out.println is Java statement which prints argument passed to console.

System is a class
out is static object of type PrintStream.
println is a method

Let’s go through more details.

System: System is class in the package “java.lang”.Since java.lang package is imported into in every program by default,so java.lang package does not require an explicit import statement.

out: out is static member of System class and is an instance of out object is connected to standard output stream of operating system, so any argument passed to out object goes to OS output stream.

println: println is method of PrintStream class.This method is overloaded to print message to output which is generally console or file.

So you can imagine structure as below.

Does System.out.println impact performance?

Yes, System.out.println can impact performance if overused. When you call println, it internally calls write() and newLine(). Both write and newLine contain synchronized but have little overhead.

If multiple threads write at the same time, then performance can suffer but major cost is to add character to buffer and print them.

In any case, you should not have any System.out.println in the production environment.

That’s all about System.out.println in java.


Join Our News Letter – Stay Updated

Subscribe to Awesome Java Content.

Add Comment

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.
You can like our facebook page Java2blog