On Windows 11 some applications require you to set both the JAVA_HOME variable and include Path to JDK Bin Directory.
In this case, you need to edit both Java Home and the Path on the User variables and System Variables. System variables/User variables don't need the \bin reference but the Path needs the \bin reference
Setting JAVA_HOME
Simply copy-paste the file path to the JDK folder exluding \bin part:
C:\Program Files\Java\jdk-21.0.1

Setting the Path
You need to include \bin reference part:
%JAVA_HOME%\bin

%JAVA_HOME% points to the above variable file path i.e. C:\Program Files\Java\jdk-21.0.1 and then \bin is appended at the end.
Confirmation
To confirm it has been set correctly, restart Android Studio or CMD and type this command on the terminal:
java -version
You should see this this message:
java version "21.0.1" 2023-10-17 LTS Java(TM) SE Runtime Environment
(build 21.0.1+12-LTS-29) Java HotSpot(TM) 64-Bit Server VM (build
21.0.1+12-LTS-29, mixed mode, sharing)
JAVA_HOMEshould be uptoC:\Program Files\Java\jdk1.8.0_ 131only