Step 1
aptitude install default-jre
aptitude install default-jdk
Step 2
update-alternatives --config java
You will got a path to your Java.
Add it to the /etc/environment
file:
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java"
Step 3
source /etc/environment
digitalocean.com/community/tutorials/how-to-install-java-with-apt-on-debian-9