JAVA Syllabus
QUESTIONS & ANSWERS

What is the diference between System.in, System.out, and System.err?

In Java, System.in, System.out, and System.err are pre-defined standard streams that are used to handle input, output, and error streams respectively.

  • System.in : It is used to read input data from the console. By default, it is connected to the keyboard, and it reads input as a stream of bytes. To read input data in a more convenient format, we often use the Scanner class to wrap System.in and read data as different data types.

  • System.out : It is used to write output data to the console. By default, it is connected to the console, and it writes output as a stream of bytes. To write output data in a more convenient format, we often use the PrintStream class to wrap System.out and write data as different data types.

  • System.err : It is used to write error data to the console. By default, it is connected to the console, and it writes error messages as a stream of bytes. It is usually used to display error messages when something goes wrong in the program.

In summary, System.in is used for input, System.out is used for output, and System.err is used for error messages.

06/03/2023, 10:06 am Read : 173 times