The Wayback Machine - https://web.archive.org/web/20240118180335/https://www.geeksforgeeks.org/difference-between-system-out-println-and-system-err-println-in-java/
Open In App
Related Articles

Difference Between System.out.println() and System.err.println() in Java

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

System.out is a PrintStream to which we can write characters.  It outputs the data we write to it on the Command Line Interface console/terminal. It is mostly used for console applications/programs to display the result to the user. It can be also useful in debugging small programs.

Syntax:

System.out.println("Your Text which you want to display");

Example:

Java




// Java program to Demonstrate Use of System.out.println()
 
// Importing required input output classes
import java.io.*;
 
// Main class
class GFG {
 
    // Main driver method
    public static void main(String[] args)
    {
        // Print statement
        System.out.println("GeeksForGeeks!");
    }
}


Output

GeeksForGeeks!

Now let us come onto the next concept of System.err which is also very closely related to System.out.System.err is also a print stream. It works the same as System.out. It is mostly used to output error texts. Some programs (like Eclipse) will show the output to System.err in red text, to make it more obvious that it is error text. 

Syntax:

System.err.println("Your Text which you want to display");

Example

Java




// Java Program to Demonstrate Use of System.err.println()
 
// Importing required classes
import java.io.*;
 
// Main class
class GFG {
 
    // Main driver method
    public static void main(String[] args)
    {
        // Print statement
        System.err.println("GeeksForGeeks!");
    }
}


Output:

GeeksForGeeks!

Note:

  • System.err and System.out both are defined in System class as reference variable of PrintStream class as:
public final static PrintStream out = null;
public final static PrintStream err = null;
  • Both outputs are displayed on the same console, Most of the IDEs differentiate the error output with red color.
  • We can reconfigure the streams so that for example, System.out still prints to the console but System.err writes to a file.

Now let us finally conclude out the differences between the two which are depicted below in tabular format as follows:

System.out.println() System.err.println() 
System.out.println() will print to the standard out of the system. System.err.println() will print to the standard error.
System.out.println() is mostly used to display results on the console. System.err.println( is mostly used to output error texts.
It gives output on the console with the default(black) color. It also gives output on the console but most of the IDEs give it a red color to differentiate.

Feeling lost in the vast world of Backend Development? It's time for a change! Join our Java Backend Development - Live Course and embark on an exciting journey to master backend development efficiently and on schedule.
What We Offer:
  • Comprehensive Course
  • Expert Guidance for Efficient Learning
  • Hands-on Experience with Real-world Projects
  • Proven Track Record with 100,000+ Successful Geeks

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 03 Nov, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials