I have set %JAVA_HOME% as "C:\Program Files\Java\jdk-23".
When I echo %JAVA_HOME%, it will return "C:\Program Files\Java\jdk-23:. When I cd %JAVA_HOME%, it will take me to "C:\Program Files\Java\jdk-23".
but when I "dir %JAVA_HOME%, it will complain that
The system cannot find the path specified.
This is so strange. what’s wrong?

Incidentally, I have set my JAVA_HOME to "C:\Program Files\Java\jdk-23". But where java returns "C:\Program Files\Common Files\Oracle\Java\javapath\java.exe". Does it matter?
>Solution :
The issue is that the %JAVA_HOME% path contains spaces, which are delimiters, so it won’t find the correct file
The solution is to change your command to:
dir "%JAVA_HOME%"
cdworks because, as per the documentation,
Spaces aren’t treated as delimiters, so can contain spaces without enclosing quotation marks. For example:
cd username\programs\start menu