I wanted to use sun java with ubuntu instead of openjdk. So I installed the latest package sun-java6-jdk (or sun-java5-jdk). The java command /usr/bin/java still points to openjdk though. This is where update-alternatives comes in. This is a pretty slick solution to the problem where multiple packages provide the same command. Like the case I had.
I only had to run a couple commands
update-alternatives --display java
This command tells me what of the commands installed is the highest priority. If I want sun java to be the highest priority then I just need to make the number higher. In my case the number for openjdk was 1061. So then I just ran the following command.
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-6-sun/jre/bin/java 1100
After this I run:
$ java -version
java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) 64-Bit Server VM (build 10.0-b22, mixed mode)
Quick and elegant solution. What more can you ask for. Linux is amazing when you know what to do.