Video in progress

What are System.out, System.err and System.in?

They are the process's three standard streams: System.in is the input InputStream from the keyboard or a pipe, System.out is normal output, System.err is a separate output for errors. The last two are both PrintStreams.

📖 Answer

The OS gives every process three streams: stdin, stdout, stderr. Java exposes them through these three fields.

Why are out and err separate? Because you can redirect them separately:

java -jar app.jar > out.log 2> errors.log

In a container (Docker, Kubernetes), logs are also collected from stdout/stderr, so it is enough for a Spring Boot application to write to the console instead of a file.

One small nuance: System.out and System.err are buffered separately, so their lines can come out interleaved in the console.

Don't log with System.out.println in prod code: it has no level, no timestamp, no thread name, and you can't turn it off. That is what an SLF4J logger is for.