Skip to content

Why does print error in the console without adding System.err.println to the code? [closed]

The error print in the console if an error found while compiling the code. How does it work without adding System.err.println


Don’t confuse errors you get when compiling your code with errors that occur when running it.

Compile-time errors are printed by the compiler, not your code. Whether your code uses System.err or not isn’t relevant. The compiler has System.err.println—or something equivalent—somewhere in its own source code.

Let’s say I tried to compile this program:

class Test {
    public static void main(String[] arguments) {
        Hello world!

Does the compiler need me to use System.err in order to tell me that Hello world! is wrong? Certainly not, right? A syntax error is a syntax error.