This small trick will tell you how you can compile a java source file from another java file on the go. You do not need to run it on a different page and compile it there and then get back to this program. This will be immensely helpful for a program that has some dynamic segments of codes which need to be compiled here within. Basically what we are gonna do is  we will use getSystemJavaCompiler() method in the ToolProvider class  that returns an object of some class that implements JavaCompiler. 

1. The implementation needs  tools.jar file usually available in the libtools.jar. So you need to give the proper directory path in the class path so that we can use import javax.tools.*
Or you can use

cp /usr/java/jdk/lib/tools.jar /usr/java/jdk/jre/lib/ext/

this command above to change it from terminal.

2. Now to compile that program from within another Java file, here is the code snippet you need to use

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if(compiler.run(null, null, null, fileName + ".java") != 0) {
// Error message
}

And you are done.