Java console-based output
System.out is used to output data to the console. It is a static reference field inside the
java.lang.System class that holds an instance of
PrintStream class is present inside the
java.io package, and it provides different method to print data, like
println(). In the case of the
System.out object, these data is printed to the console in the standard output stream.
System.out.println("Welcome to JCoder!!!");
Welcome to JCoder!!!
We have already used
System.out to print our output to console in previous programs.
print()is used to print the parameters provided but it doesn’t set the cursor to a new line.
println()prints the parameters provided and then set the cursor to a new line.
String firstString = "Welcome"; String secondString = "to"; String thirdString = "JCoder"; //Print using print() System.out.print(firstString + " "); System.out.print(secondString + " " +thirdString); System.out.print("!!!"); //Set cursor to new line using println() System.out.println(); System.out.println("Have a good day!!!");
Welcome to JCoder!!! Have a good day!!!
Even though you can use