0

I have set the environment variable for Java 7 but some software are picking Java 1.8 as default. When I am checking version through command prompt it is giving different results. How and why is this happening?

C:\Users\TanuGarg>java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

C:\Users\TanuGarg>javac -version
javac 1.7.0-internal
halfer
  • 19,824
  • 17
  • 99
  • 186
Tanu Garg
  • 3,007
  • 4
  • 21
  • 29
  • you also need to remove environment variable for java 1.8 – Mustahsan Mar 18 '19 at 06:02
  • 1
    write command `where java` or `where javac` which show you where your package installed may find useful information. – Akash Shah Mar 18 '19 at 06:02
  • @Mustahsan I havnt set environment variable for java 8. – Tanu Garg Mar 18 '19 at 06:04
  • @Akash where java showing both the paths: C:\Users\TanuGarg>where java C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe C:\Windows\System32\java.exe C:\Program Files\IBM\Java70\bin\java.exe C:\Users\TanuGarg>where javac C:\Program Files\IBM\Java70\bin\javac.exe – Tanu Garg Mar 18 '19 at 06:05
  • i see two java installed one is in Oracle package and another is in IBM where only one javac found in IBM package, javac not found in Oracle. that's issue and idk how to fix it. but maybe reinstallation or set environment variable for oracle package will fix your problem. – Akash Shah Mar 18 '19 at 06:11
  • set as oracle package path https://stackoverflow.com/questions/32241179/setting-up-enviromental-variables-in-windows-10-to-use-java-and-javac – Akash Shah Mar 18 '19 at 06:22
  • One is the JRE, one is the JDK. Your JDK is a whole version behind. – user207421 Mar 18 '19 at 06:42

3 Answers3

0

this happens because you have two java versions (JRE) installed in your pc (one used by software and the other one is your jre in your JDK) and you have only one SDK version so your javac.

Solution:

Set Path variable to your JDK bin folder and remove the path of the other jre from Path Variable.

0

you can go to control panel -> java -> java (tab) -> View. This will list all the jre that are currently installed on your system(Where java will achieve the same thing). Here you can disable the jre-8 or any jre that might be latest install on your system by unchecking the Enable checkbox.

Also, if you want to run a software for a specific jre on a system that have multiple jre instanlled, you can directly go the jave jre path and run java mysoftware command from there

e.g. C:\Program Files\IBM\Java70\bin > java mycommand

Ashishkumar Singh
  • 3,580
  • 1
  • 23
  • 41
0

If you have several jdks in your environment like me then, the only thing you can do is setting a proper path variable for your desirable jdk.

In my case, i have three jdks- 1.6, 1.7 and 1.8(javafx).

My three jdk folders

I have three jdk choices depending on the path variables.

For java 8 choice, i have to set the path variable look like image below.

enter image description here

where my javac.exe file is located under the folder name

C:\DEV\COMP\Java\javafx\jdk1.8.0_152

For java 7, i just set the path again pointing another one of jdk folders - jdk7.

enter image description here

It depends on which java version you should use by changing your java path if you just set the path variable properly.

Let's see the path variables so far.

enter image description here

The default jdk version is 1.7 because first item on a path variable is pointed at the jdk 1.7 path. I get a jdk 8 version, if I move the path of jdk 1.8 before that of jdk 1.7 again.

enter image description here

tommybee
  • 2,409
  • 1
  • 20
  • 23