Create new custom variable that point to the preferred version

Set %JAVA_HOME%/bin as first entry to Path Variable

Profit!
Check with
java -version
Why not just remove the Oracle Java path entry and not worry about your JAVA_HOME placement in the Path?
You might suggest to simply remove the Oracle Java path that was prepended to your Windows PATH by the installer. Yes, I thought of that too, but the installer also copies the java.exe, javaw.exe, and javaws.exe files to C:\Windows\System32 directory, which is also in the Windows PATH variable. So rather than chase down all the possible directories that the installer put Java, and to avoid deleting the System32 files that actually may be necessary to some process somewhere, I decided that simply prepending my preferred Java Home directory to the path was best option.
Source: How to set custom Java path after installing JDK 8 – Douglas C. Ayers
Answer from Ooker on Stack OverflowCreate new custom variable that point to the preferred version

Set %JAVA_HOME%/bin as first entry to Path Variable

Profit!
Check with
java -version
Why not just remove the Oracle Java path entry and not worry about your JAVA_HOME placement in the Path?
You might suggest to simply remove the Oracle Java path that was prepended to your Windows PATH by the installer. Yes, I thought of that too, but the installer also copies the java.exe, javaw.exe, and javaws.exe files to C:\Windows\System32 directory, which is also in the Windows PATH variable. So rather than chase down all the possible directories that the installer put Java, and to avoid deleting the System32 files that actually may be necessary to some process somewhere, I decided that simply prepending my preferred Java Home directory to the path was best option.
Source: How to set custom Java path after installing JDK 8 – Douglas C. Ayers
For linux users run command sudo update-alternatives --config java
it will return the list of java JDKs you have and you can simply use its index to select your preferred version
How to downgrade Java version default installed into Azure Portal from Java 17 to Java 11
How do I switch between Java versions?
How to revert to specific Java version (i.e.: java 11.0.18 instead of java 11.0.20)
consider downgrade the target java version to 8 or 11?
Videos
So, I have two different versions of Java in my system, 8 and 16. Depending on the project, I need to switch between the two. Right now, I need to use 16, but when I run java -version I see, I'm still using "1.8.0_202".
I have changed my JAVA_HOME variable to point to the location of Java 16. Do I need to uninstall Java 8 in order to use Java 16? I'd rather not do that.
Change your PATH variable so that it has the location of the jdk5/bin directory:
- Start -> Control Panel -> System -> Advanced
- Click on Environment Variables, under System Variables, find PATH, and click on it.
- In the Edit windows, modify PATH by adding the location of your jdk5/bin directory to the beginning. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the directory as the value.
- Close the window.
- Reopen Command prompt window, and run
java -version
In the command shell:
set JAVA_HOME=C:\jdk1.6.0u24
set PATH=%JAVA_HOME%\bin;%PATH%
That will temporarily set up the environment in the command shell. Maven, Ant, etc. will pick up on your new version of Java without having to go to the Control Panel repeatedly.
Tools like Eclipse should be able to select which JDK to use in their own configuration tools for use within their environments.
Hello, how's it going?
I updated my Tumbleweed this morning, and my java-11-openjdk got updated from version 11.0.19 to 11.0.20. Since then, I've been trying to figure out a way to temporarily revert it to the previous version (until a software I use is updated and starts working with the latest Java version).
What are your thoughts on this?
java -version is running the wrong version of java.
Diagnostics:
>java -version
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)
the following is the Java related contents from the output of
PATH:
PATH=C:\ProgramData\Oracle\Java\javapath; ... C:\Program Files\Java\jdk1.6.0_45\bin
Conclusion:
From the above output we can deduce that C:\ProgramData\Oracle\Java\javapath is 1.8.0_66.
You need to change your PATH to put C:\Program Files\Java\jdk1.6.0_45\bin first.
I noticed that after checking the path per your suggestion. Windows 10 does not allow me to edit the path because it says "This environment variable is too large." I know there should be another question to deal with this separately.
You also need to clean up your path. My guess is you have a lot of duplicate entries.
I have the same problem, I have set JAVA_HOME:
C:\Program Files\Java\jdk1.7.0_75
and Path to:
%JAVA_HOME%\bin
I need run jdk 7. When I run java -version it always appear jdk 8.
I solved it with: in System Environment --> Path --> order %JAVA_HOME%\bin to first.