I want to compile my code down to Java version 1.0.
I managed to compile down to 1.1
:
$ java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-2~deb9u1-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
$ javac -target 1.2 -source 1.2 MyClass.java
(works with some warnings)
$ javac -target 1.1 -source 1.2 MyClass.java
(works with some warnings)
But the target
option does not seem to accept 1.0
:
$ javac -target 1.0 -source 1.2 MyClass.java
javac: invalid target release: 1.0
How do I target JDK 1.0?
I want my .class and .jar file to work as many systems as possible, including very old ones, including JDK 1.0. (I don't have access to a system running JDK 1.0.)
What I've tried so far:
ecj-3.0.2.jar
: It doesn't support -target 1.0
, the minimum is -target 1.1
.javac: invalid target release: 1.0
.javac: invalid target release: 1.0
.javac: invalid target release: 1.0
. This is the first JDK with Linux amd64 binaries.javac: invalid target release: 1.0
.javac: invalid target release: 1.0
.javac: invalid target release: 1.0
. (I got this error first, when I asked the question.)The reason why I believe that -target 1.0
may work is this answer: https://stackoverflow.com/a/26148408
You can use the -jo compiler command line option in order to specify options to be passed to the Java compiler such as: "-source" and "-target". In order to check the version number in a . class file you can use the javap utility that is distributed with the JDK.
The class files created by Java 8 are still executable in Java 11; however, there have been other changes in the Java runtime (library changes, etc.) that might require modification of the code. These modifications may be made in Java 8 and compiled with Java 8 making it compatible with the Java 11 runtime.
Java is backwards compatible. You use the -source option to specify the java version used for compilation and you use the -target option to specify the lowest java version to support. eg. If I specify a target of 1.4, then my program will not be able to run on java 1.3 or lower.
By default, javac compiles each source file to a class file in the same directory as the source file. However, it is recommended to specify a separate destination directory with the -d option described in Standard Options.
In Java 8 the minimum target is JDK 1.1. In Java 9 the minimum target was increased JDK 1.6 (Java 6).
Its a good thing you are trying to make your code compatible with as many java versions as possible, but since Java 6 has been out of service since 2015, really nobody should be trying to write new code that runs with Java 5 or older.
EDIT: Also, in Java 9 they introduced the --release
flag in Javac, which is the preferred option instead of -source
and -target
now. Basically --release 6
is the same thing as -source 1.6 -target 1.6
, but it also has the added benefit of setting your bootclasspath in conjunction with the target release, which is a huge convenience. In practice this protects you from setting --release 6
in the compiler, but accidentally using some new class or language feature from Java 7 or higher.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With