I am writing this post because I keep forgetting how to do it and end up trawling the web trying to find it. The Unbuntu starter guide should be the first port of call to install whatever flavour of java you want via apt.
Then this comes from 
If you want to use Sun’s Java instead of the open source GIJ (GNU Java bytecode interpreter) you need to set it as default. To list installed JVMs:
To select, for example, Sun’s JVM as provided in Ubuntu 6.06, run:
sudo update-java-alternatives -s java-1.5.0-sun
You should also edit /etc/jvm and move /usr/lib/jvm/java-1.5.0-sun to the top of JVMs offered.
To set the JAVA_HOME environment variable I followed this 
You can find your JAVA_HOME using the locate command for a file belonging to the JDK.