I had this problem (Java 1.8 vs. Java 9 on Windows 7) and my findings:
short version
seems by default (due to path input)
c:\ProgramData\Oracle\Java\javapath\java -version
select the version you need (test, use the tab ending in cmd, not sure what these numbers represent), I had 2 options, see the more detailed version for more information
c:\ProgramData\Oracle\Java\javapath_target_[tab]
remove the connection / link and the link to your version (the one that ends with 181743567 in my case for Java 8)
rmdir javapath mklink /D javapath javapath_target_181743567
longer version:
Reinstall Java 1.8 after Java 9 does not work. The installation sequence was jdk1.8.0_74, jdk-9.0.4 and tried to make Java 8 by default using jdk1.8.0_162 ...
After installing jdk1.8.0_162, I still have
java -version java version "9.0.4" Java(TM) SE Runtime Environment (build 9.0.4+11) Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
What I see along the way
Path=...;C:\ProgramData\Oracle\Java\javapath;...
So, I checked what it is and I found that this is a connection (link)
c:\ProgramData\Oracle\Java>dir Volume in drive C is OSDisk Volume Serial Number is DA2F-C2CC Directory of c:\ProgramData\Oracle\Java 2018-02-07 17:06 <DIR> . 2018-02-07 17:06 <DIR> .. 2018-02-08 17:08 <DIR> .oracle_jre_usage 2017-08-22 11:04 <DIR> installcache 2018-02-08 17:08 <DIR> installcache_x64 2018-02-07 17:06 <JUNCTION> javapath [C:\ProgramData\Oracle\Java\javapath_target_185258831] 2018-02-07 17:06 <DIR> javapath_target_181743567 2018-02-07 17:06 <DIR> javapath_target_185258831
These hashes don't ring, but when I checked
c:\ProgramData\Oracle\Java\javapath_target_181743567>.\java -version java version "1.8.0_162" Java(TM) SE Runtime Environment (build 1.8.0_162-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode) c:\ProgramData\Oracle\Java\javapath_target_185258831>.\java -version java version "9.0.4" Java(TM) SE Runtime Environment (build 9.0.4+11) Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
to enable Java 8 again, I had to remove the link as described here
rmdir javapath
and recreate with java i wanted
mklink /D javapath javapath_target_181743567
tested:
c:\ProgramData\Oracle\Java>java -version java version "1.8.0_162" Java(TM) SE Runtime Environment (build 1.8.0_162-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)