After installing Java in mac you can set the java home variable like below
Open besh profile
open -a TextEdit ~/.bash_profile
Set Java home
export JAVA_HOME='/usr/libexec/java_home'
export PATH=$PATH:$JAVA_HOME/bin

Now after making above entries in bash profile save the file and close it.

You can also refer below link

Please try the same and let me know if you face any further issue.