Java doc says (search cross compilation options)
By default, classes are compiled against the bootstrap and extension classes of the platform that javac shipped with. But javac also supports cross-compiling, where classes platform that javac shipped with. But javac also supports cross-compiling, where classes are compiled against a bootstrap and extension classes of a different Java platform implementation. It is important to use -bootclasspath and -extdirs when cross-compiling; implementation. It is important to use -bootclasspath and -extdirs when cross-compiling; see Cross-Compilation Example below.
-target version
Generate class files for the specified version of the virtual machine. Class files will run on the specified target and in later versions, but not on earlier versions of the virtual machine. Acceptable goals are 1.1, 1.2, 1.3, 1.4, 1.5 (also 5), 1.6 (also 6) and 1.7 (also 7). The default value for -target depends on the value of -source:
If -source is not specified, the value of -target is 1.7 If -source is 1.2, the value of -target is 1.4 If -source is 1.3, the value of -target is 1.4 If -source is 1.5, the value of -target is 1.7 If -source is 1.6, the value of -target is 1.7 For all other values of -source, the value of -target is the value of -source.
So,
javac -target 1.6 -source 1.6 yourJavaProgram.java
source share