what is a the difference between System.err and System.out

what is a the difference between System.err and System.out

The System.out writes to  the \"standard output\". The System.err writes to \"standard error\". These two streams are setup by the operating system when the Java program is executed, and can be redirected with the uses of \"|\", \">\", etc. on the command line. You can redirect the output of the System.out to any other file. The following example can help to understand the concept :

public class Test{
public static void main(String args[]){
System.out.println(\"Output of System.out\");
System.err.println(\"Output of System.err\");

First Execution -
C:>java Test
Output of System.out
Output of System.err

Second Execution -
C:>java Test > abc.txt
Output of System.err

In the second execution we diverted only the std output stream and std err stream remained unchanged. i.e., by this way, we can handle error stream separately.

Date:2015-01-09 00:00:00

Post Your Answers

User Email:

User Name:

Related Java Subjective Links

Java Subjective interview questions and answers for experienced and fresher