I have a doubt as to whether java is backward compatible or forward compatible? Also, can we run java bytecode written in JDK 11 Windows on a MAC which has JDK 8 without any complications? I'm trying to understand the concept of platform independence.
Short answer: Yes. That’s the point. Your ancient byte code, even from Java 1, will run under Java 11.
More detailed answer: There have been a few classes that have now finally actually been deleted from the standard library. But chances are that you did not use them.
Edit: I seem to have misread your question. No, you cannot run code compiled with Java 11 under Java 8. The bytecode version has been increased, and Java 8 will refuse to run it.
Java bytecode is forwards compatible. I.e., a newer JVM can run java byte code compiled for an older JVM. The other way round is not true, and the program will fail with an "unrecognized class file version" error.
If you want to go the other way round, you can force a newer JDK to compiler the code for an older JVM (by setting the language level), and as long as you're not using any syntax that's too new for that version, it should work. Note, however, that this does not prevent the code from relying on classes/method introduced in a later JDK. If you want to make sure the code is backwards compatible from that perspective too, you'll need a third party tool like Animal Sniffer.
© 2022 - 2024 — McMap. All rights reserved.
target = 11
if so then it will not work on the JDK 8 but as you wrote you have it running then thetarget = 11
can't be the case. Usually you define a target byte code level which is needed as minimum. – Anaximander