Adrian Petrescu's answer is correct.
https://stackoverflow.com/a/22842806/10090030
Additionally, you can verify your changes by running the following command in the terminal:
print $JAVA_HOME
If the changes were applied successfully, you'll see:
/Library/Java/JavaVirtualMachines/jdk-xx.jdk/Contents/Home
If the configuration is incorrect, nothing will be displayed.