Using System.out and System.err - Java Language Basics

Java examples for Language Basics:Console

Introduction

Both System.out and System.err represent instances of PrintWriter.

println method adds a line-feed character to the end of the output.

The print method is useful when you want to print two or more items on the same line.

Demo Code

public class Main {
  public static void main(String[] args) {
    int i = 64;//from  ww  w .j a  va  2 s . c  o m
    int j = 23;
    System.out.print(i);
    System.out.print(" and ");
    System.out.println(j);

  }

}

You could do the same thing with a single call to println by using string concatenation, like this:

Demo Code

public class Main {
  public static void main(String[] args) {
    int i = 64;//from  w w  w .j a va  2 s .c  om
    int j = 23;
    System.out.println(i + " and " + j);
  }
}

Related Tutorials