How to compile to target Java 1.0
Asked Answered
S

2

7

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:

  • Compiling with ecj-3.0.2.jar: It doesn't support -target 1.0, the minimum is -target 1.1.
  • Compiling with JDK 1.0: I couldn't run it, it wasn't released for Linux.
  • Compiling with JDK 1.1: I couldn't run it, it wasn't released for Linux.
  • Compiling with JDK 1.2: The Linux i386 javac binary doesn't work, it's giving me Segmentation fault.
  • Compiling with JDK 1.3: javac: invalid target release: 1.0.
  • Compiling with JDK 1.4: javac: invalid target release: 1.0.
  • Compiling with JDK 1.5: javac: invalid target release: 1.0. This is the first JDK with Linux amd64 binaries.
  • Compiling with JDK 1.6: javac: invalid target release: 1.0.
  • Compiling with JDK 1.7: javac: invalid target release: 1.0.
  • Compiling with JDK 1.8: 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

Shrink answered 10/2, 2019 at 20:12 Comment(3)
This may be a case of an X-Y problem (xyproblem.info). It seems like the real problem here is that you want to be compatible with as many running environments as possible. The key is in the phrase 'running environments'. You are extremely unlikely to find many (if any) currently patched and maintained systems that are still running Java 1.0.Fraxinella
@Jason: Nevertheless, in this question I'm interested in compiling for JDK 1.0. I already know that targeting JDK 1.1 is much easier, and there is probably very few running JDK 1.0 systems which my program won't support if I compile for JDK 1.1.Shrink
I have a Java version 1.0.2, and searching for the installer (JDK-1_0_2-win32-x86.exe) even today still finds a download location. This is however a windows only installer - other versions that might turn up are for Solaris and MacOS 7.5. No Linux version was ever availableEudora
S
3

TL;DR javac -target 1.1 (and not using any classes or methods that were added later) will make it work on JDK >=1.0.2 (released on 1995-09-16). It's not feasible to go back more, because earlier JDKs are not publicly available to try.

The javac -target ... flag value affects the minor (byte offset 4 and and 5) and major (byte offset 6 and 7) version number stored in the .class file:

  • javac -target 1.1 in JDK 1.8 generates version 45.3, supported by JDK 1.0.2 (released on 1995-09-16), JDK 1.1.* (released in 1997-02), JDK >=1.2 (released in 1998-12). [source]
  • javac in JDK 1.0.2 (from jdk-1_0_2-win32-x86.exe, run with wine on Linux) generates version 45.3.
  • For k ≥ 2, JDK release 1.k supports class file format versions in the range 45.0 through (44+k).0 inclusive. [source]
  • javac -target 1.2 generates version 46.0, supported by JDK >=1.2.
  • javac -target 1.3 generates version 47.0, supported by JDK >=1.3.
  • javac -target 1.4 generates version 48.0, supported by JDK >=1.4.
  • etc.
Shrink answered 11/2, 2019 at 15:24 Comment(0)
B
6

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.

Birk answered 10/2, 2019 at 20:16 Comment(13)
Thank you for your opinion! I'm not using Java 9, as you can see in the question java -version. I'm ready to install and use whatever Java version is needed to make javac -target 1.0 work. Do you know how I can make it work?Shrink
I can't accept this answer, because it doesn't answer my question: How do I target JDK 1.0? (I'm not looking for advice on which JDK version I should be targeting.)Shrink
Yep, I understand you are using Java 10, I was saying the minimum level was changed as of Java 9 and moving forward. So this statement also carries forward to Java 10.Birk
No, I'm not using Java 10, see java -version in the question. openjdk version "1.8.0_181" is what is available right now on my computer, but I'm ready to install whatever is needed to make javac -target 1.0 work.Shrink
Your immediate question was how to target JDK 1.0 yes, but taking a step back from that requirement, your goal seems more like "I want my .class and .jar file to work as many systems as possible", which my answer does address. If you do truly need to target JDK 1.0, I understand if you prefer to keep searching for an answer to that. I think you can use a maven compiler toolchain but I've never used that myself.Birk
Ah yes your java -version output does say JDK 8. I must have mistook one of the "1.0"'s for a "10" -- my badBirk
I've clarified the question now that I'm indeed targeting JDK 1.0 (in this question), and I'm waiting for an answer which will help me do so.Shrink
You can download all JDKs back to 1.1 in the Oracle archive (oracle.com/technetwork/java/javase/archive-139210.html). Have you tried that already?Whitworth
@dunni: JDK 1.0 was never released for Linux, and I only have access to Linux systems right now. JDK 1.2 is giving me a Segmentation fault. If I get anything working, I'll post an answer myself. ecj-3.0.2.jar is not able to target JDK 1.0 either.Shrink
Super old JDKs may not work with modern operating systems. IIRC JDK 5 can compile all the way back to 1.0, perhaps try that one?Birk
@AndyGuibert: JDK 1.5 is giving me: javac: invalid target release: 1.0, so does JDK 1.6. And JDK 1.5 is the first JDK which was released for Linux amd64.Shrink
just curious, why do you need to compile to JDK 1.0? Many library developers, including myself, have the same goal as you (to work with as many systems as possible), and compile with a target of JDK 7 or 8.Birk
The first sentence of this answer is factually incorrect: in fact, for javac in JDK 1.8 the minimum is -target 1.1. Near the top of the question it's indicated that javac -target 1.1 -source 1.2 works.Shrink
S
3

TL;DR javac -target 1.1 (and not using any classes or methods that were added later) will make it work on JDK >=1.0.2 (released on 1995-09-16). It's not feasible to go back more, because earlier JDKs are not publicly available to try.

The javac -target ... flag value affects the minor (byte offset 4 and and 5) and major (byte offset 6 and 7) version number stored in the .class file:

  • javac -target 1.1 in JDK 1.8 generates version 45.3, supported by JDK 1.0.2 (released on 1995-09-16), JDK 1.1.* (released in 1997-02), JDK >=1.2 (released in 1998-12). [source]
  • javac in JDK 1.0.2 (from jdk-1_0_2-win32-x86.exe, run with wine on Linux) generates version 45.3.
  • For k ≥ 2, JDK release 1.k supports class file format versions in the range 45.0 through (44+k).0 inclusive. [source]
  • javac -target 1.2 generates version 46.0, supported by JDK >=1.2.
  • javac -target 1.3 generates version 47.0, supported by JDK >=1.3.
  • javac -target 1.4 generates version 48.0, supported by JDK >=1.4.
  • etc.
Shrink answered 11/2, 2019 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.