Search code examples
javaoutprintlnprintstream

Why is there difference between out.println and err.println?


  1. System.class contains "out" and "err" object of Printstream class.
  2. System.class is declared static.
  3. println() is a overloaded method in Printstream class which have (out and err objects)

if we execute System.out.println("Xys"); and System.err.println("Fdfd");

They both should work Exactly the same as out and err are the objects of the same class except for the fact that they don't.

Why out.println() prints in black and err.println() prints in red.


Solution

  • Because the IDE you're using prints stderr in red, and stdout in black.

    This has nothing to do with Java, and everything to do with the environment you're in–it's what's doing the coloring, not Java itself, which doesn't care how its output is actually rendered.