You're going to have big headaches if you try to handle multiple java versions manually. The best option is to delegate this to a third party tool, quite some already exists to overcome the issue. The best one and recommended by several frameworks (https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#getting-started.installing.cli.sdkman) is sdkman:
https://sdkman.io/
Follow windows installation:
https://sdkman.io/install#:~:text=Windows%20installation
Then do:
sdk list java
You will see something like:
================================================================================
Vendor | Use | Version | Dist | Status | Identifier
--------------------------------------------------------------------------------
Corretto | | 21 | amzn | | 21-amzn
| | 21.0.1 | amzn | | 21.0.1-amzn
| | 20.0.2 | amzn | | 20.0.2-amzn
| | 20.0.1 | amzn | | 20.0.1-amzn
| | 17.0.9 | amzn | | 17.0.9-amzn
| | 17.0.8 | amzn | | 17.0.8-amzn
| >>> | 17.0.7 | amzn | installed | 17.0.7-amzn
| | 11.0.21 | amzn | | 11.0.21-amzn
| | 11.0.20 | amzn | | 11.0.20-amzn
| | 11.0.19 | amzn | | 11.0.19-amzn
| | 11.0.18 | amzn | local only | 11.0.18-amzn
| | 8.0.392 | amzn | | 8.0.392-amzn
| | 8.0.382 | amzn | | 8.0.382-amzn
| | 8.0.372 | amzn | installed | 8.0.372-amzn
Install what you need with:
sdk install java 20.0.2-amzn
Then switch among versions with:
sdk use java 20.0.2-amzn
C:\Program Files\jdk8\bin\java --versionor whatever the correct path is where you installed java 8JAVA_HOMEbut also thePATH.PATHPATHenvironment variable. The first found executable will be executed.java --versionorjavac --versiondoes not show all existing installations, it only shows the version being executed. (JAVA_HOMEis not used by Java itself, some external tools use it instead of relying on thePATH)