简体   繁体   中英

Between Runtime and compile time jdk version , which one can be greater

Which one of the two, runtime version and compile time version of a java program or a jar, should be greater or equal to the other? Edit : Also what should be the version of JRE System Library?

  • So, my understanding is that you are compiling a java application with jdk1.6 and running the same application on aa runtime which is based on jdk1.8. (for example, it could jdk1.7 too here)
  • Generally, JDK/JRE would be designed in such a way that it is backwards-compatible.
  • It would be better to use a runtime environment version (JVM) that is greater than or equal to the compile version and not vice-versa.
  • JDK(Compile-Version) <= JDK(Runtime-Version) - Correct
  • JDK (Compile-Version) >= JDK(Runtime -Version) - Incorrect
  1. Java is backward compatible, most of the time you'll be able to run code compiled with the older jdk on a newer runtime.
  2. When developing with the newer jdk you can specify what target vm versions you want to support.

So both scenarios are quite possible: code compiled with older jdk running on newer runtime, and code compiled with newer jdk running on old runtime.

You should ideally always be running a Java program using a runtime environment which is the same or newer than what was used to build it. This is because Java generally ensures backwards compatibility to some extent. However, forwards compatibility is not guaranteed.

For example, if you built a Java program using version 1.7, it would be expected to run in a 1.8 JRE. But the reverse is not true, namely that a 1.8 program might not run correctly in an older 1.7 JRE.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM