Java Development Kit 1.7 and earlier

I am currently working on the standard version java 1.7

and I really like the new features:

  • Nio

    (new input out)
  • no redundant code with collections
  • ...

I want to know if there is a way to switch the class I want to execute, depending on the version (JRE)java runtime environment

it will be deployed.

+3


source to share


3 answers


First you need to create some kind of application to run the program to check the JRE version and then you can use the JAR for that JRE version. Your code cannot be compiled to newer JRE versions and executed in an older format. This is why you need to run a launcher application targeting a very old JRE.

As a side note, you can get the JRE version your program is running on using:



System.getProperty("java.version")

      

+2


source


A Java class file is almost always binary compatible with newer versions of the language (and a few exceptions, such as using a enum

pre-added keyword, are quite rare). If you restrict your use of functions to the "lowest common denominator", you can compile back an arbitrary version. This goes to show that Java 7 is quite long in the tooth right now and I found Java 8 remarkably stable. Finally, if you prefer to use new language features (like lambdas), you cannot use an earlier version of the language.



+2


source


You can create two compiled assemblies for both versions to use the language feature differently and run them on jre 7, but you just need to update your code compatibility and runtime to 1.8 (even better).

+1


source







All Articles