install and switch between java 7 and java 8 in windows

18.9k Views Asked by At

I am on widows and also using eclipse. Currently I am using java 7. Now I want to use java 8. but i cannot uninstall java 7 as some of my old projects are working in java 7.

So how can I install both java version at same time and switch between these versions.

I want only some particular projects will use java 8.

4

There are 4 best solutions below

0
On BEST ANSWER

Install both JDKs in your system and for any project if you want to use jdk 1.8. Do this

Right click on that project->Properties->java complier->set compliance level to 1.8
0
On

Well after installing both JDK 7 & JDK 8, There are two scenarios.

1) If you are using Eclipse to run your program

In Eclipse just go to project->Properties->java complier->set compliance level to 1.8 or 1.7 accordingly

2) If you are running your program using Command Prompt

In this case, you have to enter following commands before compiling your program

  set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_102
  set PATH=C:\Program Files\Java\jdk1.8.0_102\bin;%PATH%
  java -version

you can also make a batch file of the same. just copy and paste to notepad and save it with the .bat extension

0
On

Create a script that changes the JAVA_HOME environment accordingly, for example:

@echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_11
echo setting PATH
set PATH=C:\Program Files\Java\jdk1.6.0_11\bin;%PATH%
echo Display java version
java -version

Source: https://blogs.oracle.com/pranav/entry/switch_between_different_jdk_v

1
On

If you are using Eclipse, you can set the compiler preferences with the Java version you want to use for every project.

Go to Window -> Preferences -> Java -> Compiler and there you can change the Java version.

This way, you can update your PC to Java 8 and you'll have no problem with the older projects.