install and switch between java 7 and java 8 in windows

Aman Agrawal picture Aman Agrawal · Feb 2, 2016 · Viewed 17.3k times · Source

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.

Answer

Shiva picture Shiva · Dec 21, 2016

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