Print( ) vs Println( ) statement in Java

There is a whole lot of confusion among many students regarding one of the print statements in Java. The statement is System.out.println( ).

Let us see what the confusion is.

According to a few students, print( ) statement prints the content in the same line, whereas println( ) statement prints the content in the new line or next line.

Let’s see what the actual and correct answer is.

System.out.print( ) method prints the content in the same line and leaves the cursor there only

Similarly,

System.out.println( ) method prints the content in the same line where the cursor is, but after printing, it takes the cursor to the next line or new line.

If the myth is taken as correct, the output should be:

Hello

WorldWelcome

But, when we run this code, the output is coming as given below –

Thus we can see that, the println( ) statement, which is the second line, is printing the content in the same line where the first line i.e. print( ) statement printed the content. Both the statements print on the same line, whereas after printing, println( ) statement takes the cursor to the next line, and the third statement, which is a print( ) statement, prints the content in a new line.

© Spondon Ganguli, 02 August 2023