Can newer JRE versions run Java programs compiled with older JDK versions?

后端 未结 2 845
有刺的猬
有刺的猬 2020-11-29 18:00

This may be a stupid question, but would I encounter any problems running Java programs and associated libraries compiled in Java version 1.6 and 1.7 (I\'m

2条回答
  •  孤独总比滥情好
    2020-11-29 18:26

    You would not encounter any problems - that's the magic of Java -it's backwards compatible.You can run almost all code from Java 1 on Java 8. There's no reason why Java 6 code won't run on a Java 8 Runtime.

    What is interesting, is that for applications written in, let's say, Java 1.4, you even have speed increases when running them on later runtimes. This is because Java is constantly evolving, not just the language known as "Java", but also the JVM (Java virtual machine). I still have source code from more than 10 years ago that still work, as expected in the latest JVM.

    If you want to target, let's say, a Java 5 VM, then you can do that with the Java 8 SDK tools. You can ultimately specify which target VM you wish to support, as long as you bear in mind that a version 5 VM might not support all the features a version 8 VM will.

    I've just tested code I wrote in Java 5 against the new Java 8 runtime and everything works as expected, so, even though we have a more powerful language and runtime now, we can continue to use our investments of the past. Just that alone makes Java a great development choice for companies.

提交回复
热议问题