First step is to find where is java installed. For that open terminal and type the below command
/usr/libexec/java_homeThis command will output the location of java installation directory something like this depending upon the version of jdk installed
/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/HomeNext step is to set PATH environment variable. Execute the below command in Terminal
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home
export PATH=${PATH}:$JAVA_HOME/bin