Ubuntu 12.04 is a LTS (Long Term Support) release, for desktop as well as server edition. Just after a fresh install of Ubuntu 12.04, you need to install few things to get everything running, atleast for common tasks (you may find my previous post useful – things to do after a fresh install of Ubuntu 12.04).
Now, you want to execute Java programs then you must – so you just need to install a JRE (Java Runtime Environment, includes Java Virtual Machine, JIT (Just in Time compiler, IcedTea plugin)) and you’re ready to run Java Applications and Applets (not so popular anymore, JavaScript rocks!).

But, remember if you want to develop Java Applications then you need more (JDK, Docs etc) than just a JRE. So checkout this post – Install JDK on Ubuntu 12.04 if you want full development environment rather then just the run time environment.
Installing JRE/Java on Ubuntu 12.04
There are many implementation of Java Runtime environment but we will stick to the Open Source implementation of Java – OpenJDK (Open Java Development Kit). The latest stable version is openjdk-7 (although v 8 developer preview version is also available). a terminal (hit Ctrl+Alt+t, to open a bash shell or terminal or whatever shell (such as zsh) you prefer) and execute these command(s) –
sudo apt-get install openjdk-7-jre
(The package size is around ~30MB)
openjdk is different from oracle java.i am unable to execute some jars in openjdk and shifted to oracle one