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.

Related Posts

  • 22 October

    How is java distributed

    Introduction Java is considered to be the most secure platform and programming language. Java was developed in 1995 by Sun Microsystems. It is the most commonly used language among developers, which is easy to understand and code. Java enables you to build several applications. It allows you to run those applications on a single machine […]

  • 26 March

    Java boolean default value

    In this post, we will see what is default value of boolean and Boolean in java. 💡 Did you know? The Default value of boolean is false and wrapper class Boolean is null. Here is the example to demonstrate the same. [crayon-60066103762c8897770722/] Output: Default value of boolean: false Default value of Boolean(Wrapper): null As you […]

  • 22 December

    Caesar Cipher in Java

    In this post, we will see about Caesar Cipher in Java. In cryptography, we used to study different algorithms or techniques to encrypt and decrypt a different sets of messages to gain confidentiality, integrity or say some kind of security. Usually, these things are achieved by implementing such kind of techniques, sometimes clubbed with other […]

  • 01 April

    Java float vs double

    In this post, we will see the difference between float and double data types in java. As you might know, float and double both can be used to represent floating point number in java. We will see the difference between float and double and also when to use double vs float. Similarities between double and […]

  • 28 October

    How to take input from user in java

    In this post, we will see how to take input from user in java. There are times when you want to take input from user and run program according to user input. There are many ways to take input from user and some of them are: Using Scanner Using BufferReader Using  Scanner class Scanner class […]

  • 28 September

    Top 5 online programming courses you can take to improve your career

    The beauty of programming is that you are as good as your programming skills. Learning programming languages hold many benefits. Programmers are highly sought out and their skills are valued by most companies. But there is more to programming than employability. When you learn how to program, you open new doors for yourself. You could […]

Leave a Reply

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

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.