Can a program created using Java 8 run on Java 7?

I am a bit confused.

  • Oracle says Java 8 is very compatible with Java 7 (back). But, what features exist that a Java 8 program can successfully run on Java 7 (SE / EE)?

  • If the first point is correct, will Java 8 applications be deployed and run on the Java 7 support server? e.g. Tomcat 8 or WildFly?

+41
java java-8 backwards-compatibility java-server
Mar 24 '14 at 13:11
source share
6 answers

In general, no.

Backward compatibility means that you can run a program in Java 7 during the execution of Java 8, and not vice versa.

There are several reasons for this:

  • Bytecode is versioned, and the JVM checks to see if it supports the version found in .class files.

  • Some language constructs cannot be expressed in previous versions of bytecode.

  • The new JRE has new classes and methods that will not work with the old ones.

If you really want to really (hint: you won’t do this), you can force the compiler to view the source code as one version of Java and emit bytecode for another using something like this:

javac -source 1.8 -target 1.7 MyClass.java 

( same for Maven ) and compile with JDK7, but in practice it will work more often than work. I do not recommend doing this.

EDIT : JDK 8 does not seem to support this exact combination, so this will not work. Some other version combinations work.

There are also programs for converting newer Java programs to work with older JVMs. To convert Java 8 to 5-7 you can try https://github.com/orfjackal/retrolambda . To get below 5, you can choose one of them: http://en.wikipedia.org/wiki/Java_backporting_tools

None of these hacks will give you new Java 8 classes and methods, including functional programming support for collections, threads, time APIs, unsigned APIs, etc. Therefore, I would say that it is not worth it.

Or, since you want to run Java 8 JEE applications on the application server, just run your entire Java 8 server, it might work.

+65
Mar 24 '14 at 13:12
source share

Backward Compatibility Tool

You can perform the lower configuration in a higher configuration rather than Vice-Versa .

+10
Mar 24 '14 at 13:17
source share

Well, there is an option - target , which allows you to configure the class file format of previous versions of Java. However, this does not eliminate or detect things such as using classes or methods implemented in the JDK API after the target version.

+4
Mar 24 '14 at 13:23
source share

No backward compatibility means that Java7 programs will run under Java8, but the opposite is not always true

You can also check Oracle Limit Backward Compatibility

+3
Mar 24 '14 at 13:14
source share

In general, new versions should provide backward compatibility, so people should not give up their work and can be easily updated. Another option (a newer version working in the old version) is not necessary, because if you use some new implemented function, this function obviously does not exist in the previous version and will not work.

Hello

+2
Mar 24 '14 at 13:18
source share

I created stubs from WSDL compiled in java 8 and was able to deploy them to a server with java 1.6 jvm on it.

0
Mar 29 '16 at 0:13
source share



All Articles