In development environment I prefer to use Oracle JDK rather than OpenJDK. The easiest way to install any applications in Ubuntu is from repository. To install Oracle JDK you must add its repository. These are the commands.
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java7-installer
If you have installed other version, e.g Java 6 or Java 8, you can update your system environment by this command.
$ sudo update-java-alternatives -s java-<version>-oracle
You can setup Java environment variables by this command.
$ sudo apt-get install oracle-java7-set-default