In this tutorial, we shall make Java Environment Setup for your Windows, Ubuntu, or Mac machine, to start Java programming.

Install Java

To get started with Java development, we need to make our computer or PC ready with Java.

Following are the steps to get your PC ready with Java programming language :

  1. Install JDK.
  2. Setup Environment Path.
  3. Verify the Java installation.

1. Install Java Developement Kit JDK

JDK contains everything that is required for writing a program, compiling it to byte code and running it on your machine. JDK is comprised of following components :

  • Java Language – which specifies the syntax and core components.
  • Tools and Tool APIs – these are the packages which make life easy in programming.
  • JRE – The environment for running the java byte code.

2. Download latest JDK

Based on your operating system, Linux/Mac OS X/Solaris/Windows, and 32bit/64bit, download a jdk package from the below url
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
And follow the instructions of the installer.

3. Setup Java Path

For the Operating System to know about the location of java executor, Environment variables are to be setup.

Setup Java Path in Windows

Following is a step by step guide to setup Java Path in Windows computer

  1. Go to Advanced Environment Variables Window, Click on Windows button and navigate through the path
    Control Panel -> System and Security -> System -> Advanced system settings -> Advanced -> Enviroment variables -> Advanced
  2. Edit “Path” environment variable, create new variable with name “Path” if already not existing
  3. Append the path of the java executable (path of java.exe in the Java installed folder) to the “Path” environment variable. For example, if path is C:\WINDOWS\SYSTEM32 , make it C:\WINDOWS\SYSTEM32;C:\Program Files\Java\jdk1.7.0_40\bin  assuming the path of your java installation to be C:\Program Files\Java\jdk1.7.0_40\bin.

Setup Java Path in Ubuntu

Following is a step by step guide to setup Java Path in Windows computer :

Step 1: Open a Terminal and run the following command to edit environment variables

$ sudo nano /etc/environment

Provide the password if prompted for.

Step 2: Add JAVA_HOME to the file. Append the following line to the end of the file /etc/environment.

JAVA_HOME=”/usr/lib/jvm/open-jdk”

Replace the value with your Java Installation Path.

Step 3: Save the file and exit.

4. Verify the installation of Java

Let us check if Java has been installed correctly. Open command prompt in Windows or terminal in Ubuntu and run the following command

$ java -version

If Java is visible in the environment, javaw.exe responds to the command java -version with the result shown in the following picture.

Java Environment Setup
Java Version

The result to java -version, from the above picture notifies us the following:

  1. “1.8.0_111” is the version of JDK installed in the computer (running on OS : ubuntu 16.04)
  2. “1.8.0_111” is the version of JRE
  3. Java Virtual Machine is running in mixed mode. There are two basic modes namely Server mode and Client mode, in which Server mode is optimized for long running and Client mode is optimized for maximum performance. Running in mixed mode result in best of Client and Sever modes : long running and better performance.

Multiple JREs or JDKs

Multiple JREs and JDKs could be installed alongside one another and any of the installed could be used for compiling or executing a java program.

Conclusion

In this Java Tutorial – Install Java, we have successfully installed Java and setup Java Path in the environment variables. Now the computer’s environment is ready to handle java development. In our next Java Tutorial we shall see some of the Integrated Development Environments (IDE) for Java that make Java Programming Development easy, followed by our first program in Java – HelloWorld.java.