I was deploying an application to the Google App Engine using Java, and I encountered some problems with the version of Java, GAE uses Java EE 5 so you need to compile with at most JDK 7 and I have installed JDK 8 so in order to downgrade without uninstall it. Use alternatives.
I found that Java was installed on /usr/lib/jvm so I download the version that I need from Java web page and unziped it. And it’s a folder like jdk-1.7xxx so move it to /usr/lib/jvm
Now in order to create the alternatives just type the following commands.
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1
Changing the directories for the ones that you already moved to the folder. With this you just said to Ubuntu that he has alternatives to use when someone types the command java, javac or javaws. but it still uses the one that already has, so in order to change that use:
sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config javaws
And between each one of the commmands Ubuntu will ask you which one of the implementations you wish to use, type the one you need and that’s all.