Install Java



In the introductory chapter, we decided to use Java as the programming language for the development process. For using it, we need to install Java in our system. I am providing installation steps for Windows, Linux, and MacOS. Depending on the operating system you have, follow the installation process.

Before installation, we need to download the Java for developers from the official website of Oracle. You may log on to Oracle website and navigate to the executable file for your system or just click here to the executables download page. Accept the agreement and download the one which fits your computer system.

For windows:

For Linux:

For Android programming, you must have installed GUI version of Linux.

Open a terminal and switch to root user using command

sudo su

Copy the downloaded file (current version of java is jdk1.8.0_144, change it with the version you have downloaded) in /opt folder and extract it using command

cd /opt
tar xzf jdk1.8.0_144.tar.gz

now navigate to the extracted folder using the following command:

cd jdk[press-tab]

using alternatives command install and configure Java

alternatives --install /usr/bin/java java /opt/jdk1.8.0_144/bin/java 2
alternatives --config java

Select the current Java by pressing the prefix numeric key

In same way install javac and jar

alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_144/bin/jar 2
alternatives --set jar
alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_144/bin/javac 2
alternatives --set javac

Check the version of Java currently active

java -version

Set the environment variable

# export JAVA_HOME=/opt/jdk1.8.0_144
# export JRE_HOME=/opt/jdk1.8.0_144/jre

configure the PATH variable for Java

# export PATH=$PATH:/opt/jdk1.8.0_144/bin:/opt/jdk1.8.0_144/jre/bin

To presist these values over system reboot, add these variables in /etc/environment file

For MacOS:

  • You have downloaded the dmg file for your MacOS, double click on file to start the installation process.
  • A Java development kit installation pop up will appear, double click on the icon shown.

    Java installation

  • It will initiate the process and show the introduction of JDK installer, click on continue button.
  • On Installation type page, it will tell you how much storage is required to install JDK, if you have that much storage, then click continue again. Enter the password of current user and press enter.

    Install Java on MacOS Storage requirement

  • Depending on your computer, it will take some time in installation.
  • Once the installation is complete, a summary page and successful installation message are served. Click on close to complete the installation process.
  • To verify that you have successfully installed Java on your Mac open terminal and run command.
  • java -version

Verify Java version on MacOS

If you get the message something like shown in the image, then Java is installed successfully. If you find any error, follow the process once again in the same sequence.

Now you have successfully installed Java, let's move further and learn how to install Android Studio.