Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we install two versions of Java JDK on Windows?

Tags:

java

java-8

I have created an executable JAR file developed on Java version 8. The JAR file was opening on double click. But as the Oracle applications support only Java 6, I had to install JRE 6, but then after the JRE 6 installation, my executable JAR file is not opening.

I have set the JDK 8 bin path in Path environment variables. Is there a solution for this problem? Why is the JAR file not opening after two Java versions in the system?

JAR should open even if two versions 6 and 8 of Java are installed in the system.

like image 266
quick_coder Avatar asked Apr 01 '19 05:04

quick_coder


3 Answers

I am not sure if this solution going to work or not. Try to run command java -version and look if it returns java 6 or 8 path. Also try to give path of JDK 8 as JAVA_HOME variable and add that into path like this path=%JAVA_HOME%/bin and see if it works. If you get the java 6 as java version try to use above method and then install JRE 6

like image 27
Akshaya KAushik Avatar answered Oct 18 '22 20:10

Akshaya KAushik


You are facing a backward compatibility problem. Backwards compatibility means that you can run a Java 6 program on a Java 8 runtime, but not the other way around.

You can run a lower configuration on a higher configuration, not vice-versa

There are several reasons for that:

  1. Bytecode is versioned and the JVM checks if it supports the version it finds in .class files.
  2. Some language constructs cannot be expressed in previous versions of bytecode.
  3. There are new classes and methods in newer JREs which won't work with older ones.

If you really, really want (tip: you don't), you can force the compiler to treat the source as one version of Java and emit bytecode for another, using something like this:

javac -source 1.8 -target 1.6 MyClass.java

You can compile your code to Java 1.6 bytecode using JDK 1.8. Just take care of the following:

  • -source=1.8 and -target=1.6 compiler options
  • If you use Maven, consider having two pom.xml files, with an optional parent file.

Source: Can program developed with Java 8 be run on Java 7?

like image 197
Vishwa Ratna Avatar answered Oct 18 '22 18:10

Vishwa Ratna


Hi All Thank you for your response. I kept java6 and reinstalled java8 and now forms and jar both are working!.

like image 42
quick_coder Avatar answered Oct 18 '22 18:10

quick_coder