update-alternatives: warning: /etc/alternatives/java is dangling

Assuming you installed the OpenJDK6 with:

sudo apt-get install openjdk-6-jdk

In Ubuntu 64 bit, make sure the paths are valid for your installation (change if using 32bit version):

/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java

/usr/lib/jvm/java-6-openjdk-amd64/bin/javac

Setup update-alternatives:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java-6-openjdk-amd64/bin/javac" 1

sudo update-alternatives --set java /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/java-6-openjdk-amd64/bin/javac

Alternatively, make sure the correct version is checked for both Java and compiler:

sudo update-alternatives --config java
sudo update-alternatives --config javac

List the installed Java alternatives with:

sudo update-alternatives --list java
sudo update-alternatives --list javac