If you switch versions often (e.g., between Java 8 and Java 17), manually editing variables is tedious. Developers use a tool called (similar to Ruby's rbenv or Python's pyenv).

java -version

Close and reopen your terminal, then:

(only once!):

@echo off set /p version="Enter Java version (8, 11, 17, 21): " setx JAVA_HOME "C:\Java\jdk-%version%" /M echo Switched to Java %version%. Restart your command prompt.