Take the 2-minute tour ×

I found this code online about the JavaCompiler

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
int result = compiler.run(null, null, null,

And it says for the compiler.run(null, null, null that these three nulls are the default System.in, System.out and System.err respectively. But what do these values actually do as I cannot find the API for these? Could someone please explain?

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

The Javadoc is here.

int run(InputStream in, OutputStream out, OutputStream err, String... arguments)

Run the tool with the given I/O channels and arguments. By convention a tool returns 0 for success and nonzero for errors. Any diagnostics generated will be written to either out or err in some unspecified format.

    in - "standard" input; use System.in if null
    out - "standard" output; use System.out if null
    err - "standard" error; use System.err if null
    arguments - arguments to pass to the tool 
    0 for success; nonzero otherwise

As for System.in, System.out, and System.err those are global streams that (by default) connect to STDIN, STDERR, and STDOUT. These three are set up by the operating system when the JVM starts. You can pipe them to files, or they just write to (read from) the console.

In this case, you would use the parameters to inspect the compiler output from your program (rather than just sending it out to the user). This is where the "diagnostics written out in some unspecified format" come in.

share|improve this answer
add comment

You can specify your own streams instead of relying on standard System streams. E.g., if you want to redirect an output to some file, you can create File output stream, and pass to #run call.

share|improve this answer
add comment

JavaCompiler is javax.tools.JavaCompiler and it implements javax.tools.Tool interface, see javadoc for javax.tools.Tool#run method.

share|improve this answer
add comment

Your Answer


