In this Tutorial we are describing you the way to compile the java file with the help of the java program. The steps involved for compiling the java file from the program are described below: For this we are taking a class Compile Hello, Inside the main method we include the following -
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler():-Thi Creating an interface named compiler.JavaCompiler is an Interface to invoke Java programming language compilers for programs.
int result = compiler.run(null, null, null,"src/Hello.java"):-This is the method of the interface JavaCompiler.This method generally invokes the tool to run with the given I/O channels and arguments.
Output of the program
|Compile result code = 0|
Note:-The output shown above is not sufficient .you can check that the class will be generated to the particular directory which you have given above.
Recommend the tutorial