What is the difference between using javac and javax.tools.JavaCompiler?

javac (as “java compiler”) is an executable, which could be theoretically even a platform-dependent executable or a script. This is called to compile a .java to a .class. On windows is its name javac.exe, and it is normally somewhere below C:\Program Files*\jdk*\bin. This compiler was developed in java as well. That means, if we start … Read more

javac source and target options

source: The version that your source code requires to compile. target: The oldest JRE version you want to support. Be sure to also set bootclasspath to ensure your program will work on older VMs. From the javac documentation: Cross-Compilation Example The following example uses javac to compile code that will run on a 1.6 VM. … Read more

Differences between classpath and sourcepath options of javac

-classpath classpath Set the user class path, overriding the user class path in the CLASSPATH environment variable. If neither CLASSPATH or -classpath is specified, the user class path consists of the current directory. If the -sourcepath option is not specified, the user class path is searched for source files as well as class files. -sourcepath … Read more