Getting Started

1 minute read

This tutorial is targeted to Java SE 8 version.

Java Installation

Java developement kit (JDK) and Java Runtime Environment (JRE) is available for varity of platforms. Some operating systems comes with pre-installed Java.

To check Java is installed on your local machine; run below command on terminal or command line interface:

Command:

java -version

If you have Java installed, you should see an output like this:

java version "12.0.1" 2019-04-16
Java(TM) SE Runtime Environment (build 12.0.1+12)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)

Note: If Java is not installed on your computer then it must through something similar error as below:

-bash: java: command not found

Installing the Default JRE/JDK

The fastest and easiest option for installing Java is using the version packaged with Ubuntu. Specifically, this will install OpenJDK 8, the latest and recommended version.

First, update the package index.

$ sudo apt-get update

Next, install Java Development Kit (JDK). It contains JRE and JDK both.

$ sudo apt-get install default-jdk

Installing the Oracle JDK on Ubuntu

Oracle JDK is official version distributed by Oracle. Following are the steps:

$ sudo apt-get install default-jdk

Note: Linux has various distributions. For this tutorial I will be taking example of Ubuntu OS.

Following are the commands to install Java Development Kit (JDK) Java SE 8 on Ubuntu machine.

Install Java on Mac OS

Install Java on Windows OS

Hello World Program

Following is the simplest Hello World program in Java!

Car.java

public class Car {
  public static void main(String[] args) {
    System.out.println("Hello World");
  }
} 

Output:

Hello World

Updated: