If you want to run a Java app on a fresh Ubuntu server, (say Minecraft) then you first need to install the appropriate Java runtime. You can do this as follows:

Update the apt repository with the following command:

sudo apt-get update

Then check if Java is already installed:

java -version

Install the Java Runtime Environment with the following command:

sudo apt-get install default-jre

And for the Java Development Kit, use this:

sudo apt-get install default-jdk

Once you’re done with that, pretty much every Java app should run on your server.

Installing Java 8

Add the Java 8 repository:

sudo add-apt-repository ppa:webupd8team/java

Update the repositories:

sudo apt-get update

Install Java 8:

sudo apt-get install oracle-java8-installer

You need to accept the license terms.