Differences between System.out x System.err x System.in?

Asked

Viewed 1,184 times

6

I didn’t find any debate on this question here in the community so I decided to create this topic. Follow a well-commented question among beginners in the Java language when it comes to data manipulation.

  • What is the difference between the three commands?
  • Which should be used in each case?
  • And which is the most effective?
  • As no one linked the documentation: https://docs.oracle.com/javase/7/docs/api/java/lang/System.html

  • Thank you so much for the @diegofm edition, I forgot to quote the questions separately as topics here!

2 answers

4

System out. is the standard output of the system you are using. System.err is the default system error output. In a normal console application, both will probably print on the console. But you can reconfigure the outputs to, for example, make the errors printable into a text file, and leave the System out. screen printout.

Already the System in. is the system input standard, like InputStream. It is already open, and ready to receive data. Typically, it corresponds to the keyboard or any data source specified by the environment, or by users.

System in. --> Receives data

System out. and System.err --> They output data. They can be reconfigured to write in different places

1

System in.

Standard input of type InputStream, usually connected to the keyboard in terminal/console oriented programs.

System out.

Standard output of type PrintStream. Usually sends the data saved on it to the console/terminal. Often used by console-based programs as command line tools (grep, find).

System.err

Error output of type PrintStream. Works like System.out, except it is used to send error messages.

In a terminal-oriented Java application, both outputs will be the same (the command line), but you can reconfigure them so that Sistem.out keeps printing on the terminal, and System.err writes to a file, for example.

This reconfiguration can be done directly at the terminal as per these examples.

  • System.in is not only for keyboard input.

  • I know this @diegofm, so I made it clear with "generally" and "terminal-oriented programs". I know it is used in redirects and Pipes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.