-3

What is difference between

System.out.println("Programming");

and

System.err.println("Programming");

when both err and out are the object of Printstream class?

Malwinder Singh
  • 6,644
  • 14
  • 65
  • 103
  • You may read about stout and stderr as background why this two streams exist - see http://en.wikipedia.org/wiki/Standard_streams or other similar sources... – mschenk74 Sep 13 '14 at 09:41

3 Answers3

3

These are different data streams. One is the so-called standard output stream (STDOUT), the other is the standard error stream (STDERR).

lxg
  • 12,375
  • 12
  • 51
  • 73
1

yes you are right by default both stream flushing the output in console but you can reassign this two stream to different channel. Like -

System.setOut(new FileInputStream("outputfile.txt"));
System.setErr(new FileInputStream("errfile.txt"));

and try this -

try{
   System.out.println("Try");
   int i =1/0;
}catch(Exception ex){
   System.err.println(ex);
}
Subhrajyoti Majumder
  • 40,646
  • 13
  • 77
  • 103
0

You can filter t error and regular messages through the console. It's useful when you have few of one diluted in thousands of others.