Is there any difference in these statements
System.out.println(error);
AND
PrintStream ps = new PrintStream((OutputStream)S
Basically, there is no difference. The second way is too prolonged. out is a static field of type java.io.PrintStream in System class. You could directly use it instead of casting it to Outputstream and again wrapping it inside another PrintStream reference. They both are going to use the same underlying PrintStream object regardless.