JAVA Syllabus
QUESTIONS & ANSWERS

What is the diference between System.out and System.err?

In Java, System.out and System.err are two standard output streams provided by the Java Runtime Environment (JRE) for writing text data to the console or a file.

The difference between System.out and System.err is the intended purpose of the output stream:

  1. System.out: This is the standard output stream, which is typically used to write normal program output to the console or a file. The data written to System.out is typically displayed in black color in the console window.

For example:

System.out.println("This is normal output");
  1. System.err: This is the standard error stream, which is typically used to write error messages or diagnostic information to the console or a file. The data written to System.err is typically displayed in red color in the console window.

For example:

System.err.println("This is an error message");

In general, System.out is used for standard program output, while System.err is used for error messages or diagnostic information that should be distinguished from normal program output.

It's important to note that while System.out and System.err are separate output streams, they may be displayed in the console window in an interleaved or unpredictable manner, depending on the operating system and the console configuration. As such, it's generally not a good idea to rely on the order or timing of messages written to System.out and System.err when debugging or troubleshooting a program.

04/03/2023, 12:54 pm Read : 179 times