Why not set the current java version with:
sudo update-alternatives --config java
sudo update-alternatives --config javac
(and whatever else java binary you need)
Then set the following in your .bashrc or .zshrc:
#!/bin/bash
if [ -z "${JAVA_HOME}" ]
then
JAVA_HOME=$(readlink -nf $(which java) | xargs dirname | xargs dirname | xargs dirname)
if [ ! -e "$JAVA_HOME" ]
then
JAVA_HOME=""
fi
export JAVA_HOME=$JAVA_HOME
fi
This is sufficient to have a configured java enviroment, there's no need to set the PATH variable, as it's already managed by the alternatives framework.
Cheers F.