Java - Introduction Console

How to output to Console window

You can use the following method to print a message on the standard output:

System.out.println("hi"); 
System.out.print(" from book2s"); 

Demo

public class Main {
  public static void main(String[] args) {

    System.out.println("hi"); 
    System.out.print(" from book2s"); 

    /*from  w  ww . j a va2 s  .c  o m*/
  }
}

Result

Note

System.out.println() prints text to the console, after printing the text, it prints a new line character at the end of the text.

System.out.print() does not print a new line character.

The println() and print() methods are overloaded.

You can pass any Java data type argument to these two methods.

Demo

public class Main {
  public static void main(String[] args) {
    int num = 123; 
    /*from   w w  w . j a va 2  s . com*/
    System.out.println(num); 
      
    System.out.println("Value of num = " + num); 
      
    System.out.println(); 

    
  }
}

Result