I assume (from the tag) that you are using ubuntu.
list of versions of javas installed on your system:
dave@ubuntu :~$ update-java-alternatives --list java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
Please note that if you set JAVA_HOME to ~ / .bashrc, it will only be installed in your terminal sessions. If you do not export it, it will be installed only for your current shell process (not subprocesses such as mercurial).
add a line to your .bashrc:
export JAVA_HOME="/usr/lib/jvm/java-6-openjdk"
open a new terminal and test it:
$JAVA_HOME/bin/java -version && echo java seen by bash bash -c '$JAVA_HOME/bin/java -version && echo java seen by bash subprocesses'
If you want to set up an environment for all processes (not just started manually from the terminal), you can:
dave@ubuntu :~$ sudo $EDITOR /etc/environment
source share