What are System.in/out/err and what is the purpose of declaring them as public and static inside the System class?
Printable View
What are System.in/out/err and what is the purpose of declaring them as public and static inside the System class?
For a description of what they are, read the System class JavaDocs. You can work out why they are declared public and static by finding out what the 'public' and 'static' qualifiers mean. You'll find this explained in the Java Tutorials, 'Declaring Member Variables' in the 'Classes and Objects' chapter. Unfortunately, this stupid forum software won't allow me to give you the link.
I think he means this:
Java Platform SE 6
Scroll down for 'System'
But more to the point, I think you are asking what System.out/in/err are.
All three are Streams. System.out is the output stream and by default its used to print to the console/terminal/command line
For ex:
System.in is also a stream, rather in input stream. It can be used for reading from a file or from the command line.Code:System.out.println("Hello, World!");
For ex:
System.err is the same as System.out except its for printing error messages to the console with text coloring.Code:BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String txt = in.readLine();
I hope it helps :D