Installing Oracle Java on Ubuntu 14.04 LTS

You will need to run the following as the root user. To install Java 7…

add-apt-repository ppa:webupd8team/java
apt-get update
apt-get install oracle-java7-installer

…and for Java 8…

add-apt-repository ppa:webupd8team/java
apt-get update
apt-get install oracle-java8-installer

You will have to agree and accept the following licenses:

Oracle Java 8 - Accept License

Oracle Java 8 - Accept Binary License

You can quickly test both java and javac with the following….

java -version
javac -version

…or you may want to check out one of my previous posts here.

Related Documents

Using HelloWorld to Test a JDK Installation

To test that your Java Development Kit (JDK) is installed correctly, you need to write a simple Java program, compile it, and run the compiled bytecode.

[andy@home-pc ~]$ mkdir ~/java-demos
[andy@home-pc ~]$ cd ~/java-demos
[andy@home-pc java-demos]$ vim

A simple Java HelloWorld example looks like this.

class HelloWorld {
    public static void main(String[] args) {
        System.out.println("\nThe Java Development Kit (JDK) is installed and working!!\n");

You compile Java code with the javac command, and then run the resulting file with the java command.

$ ls
$ javac
$ ls
$ java HelloWorld

The Java Development Kit (JDK) is installed and working!!


You should note that although the resulting Java bytecode is a file called HelloWorld.class, you run the program without any file extension.

You could take this a step further and write some code that returns some Java system properties about the current installation.

$ ls
$ cp -v

The below code makes use of the getProperties() method, of the System import java.util.Map; class JDKInstallationTest { public static void main(String[] args) { System.out.println("\nThe " + System.getProperty("java.vendor") + " Java version " + System.getProperty("java.version") + " is installed on this system.\n"); // Print a list of Java properties System.out.println("Java Properties:"); for(Map.Entry e : System.getProperties().entrySet()) { if (((String)e.getKey()).startsWith("java")) { System.out.println(e); } } System.out.println(); } } Again, run it like so. [bash] $ ls HelloWorld.class $ javac $ ls HelloWorld.class JDKInstallationTest.class $ java JDKInstallationTest [/bash] The output will look something like this.

The Oracle Corporation Java version 1.8.0_31 is installed on this system.

Java Properties: SE Runtime Environment
java.vm.vendor=Oracle Corporation
java.vendor.url= HotSpot(TM) 64-Bit Server VM Virtual Machine Specification
java.vm.specification.vendor=Oracle Corporation
java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib Platform API Specification
java.specification.vendor=Oracle Corporation mode
java.vendor=Oracle Corporation

You can then delete the .class files if you wish, leaving only the source (.java) files.

$ ls
$ rm -v ./*.class
removed ‘./HelloWorld.class’
removed ‘./JDKInstallationTest.class’
$ ls

Related Documents

Lesson: A Closer Look at the “Hello World!” Application

Programmatically getting Version number of Java and Flash using C, C++, or Java