To start building programs in java, we need to install JDK i.e Java Development Kit.
But before we proceed, lets try to understand how everything is wired together.
For now consider that there are two main components that we would be dealing with:
- Java Compiler: Its used to convert the java code into a intermediate format called byte-code. This byte-code is what JRE understands.
- Java Runtime (JRE): Java Runtime Environment, understand the byte-code, and interprets it to machine code, respective to the architecture on which its installed.
Java Development Kit, provides us all the required tools and utilities to write Java code. It contains ‘Java Compiler’, ‘JRE’ and many other utilities, which we will take a look at later.
Note: Generally, JRE is preinstalled on most of the machines, sometimes referred to as Java-Plugin.
To Install JDK, please follow the following steps:
- Download the installer, as per your operating system from Oracle Website. Ensure that you download 32-bit or 64-bit installed as per the architecture of your machine.
- Follow the instructions in the installer, to complete the install.
- Add the
javapath, to the ‘PATH’ Environment Variable.
- Go to
Start > Control Panel > System and Security > System > Advanced system settings
- Now click on
Environment Variable, and under
System Variable, click
<Java-Directory>is the where java is installed and is generally
C:\Program Files\Java\jdk<version>, and same path should be used as
JAVA_HOME. Also ensure that path doesn’t include the bin folder.
- Now find
System Variableand select
;%JAVA_HOME/jre/bin;%JAVA_HOME/bin;at the end of
- Go to
- Now Java installation can be verified using instructions provided in Verify Installation section below.
- Your machine is now ready for Java Development
Installing Java on Ubuntu
- Use the command
sudo apt-get updateto update the
- Now use the below command to install Oracle Java on ubuntu. (Open JDK is not recommended)
$ sudo add-apt-repository ppa:webupd8team/java $ sudo apt-get install oracle-java8-installer $ sudo apt-get install oracle-java8-set-default
Java 8 is now setup on your machine.
- Open terminal, and type
sudo nano /etc/environment, this will open nano editor, to edit the environment variables.
- Now add the line
JAVA_HOME="/usr/lib/jvm/java-8-oracle", to the opened file.
- Reload this file by executing command
- Now JAVA_HOME has been set up. Please verify by executing command
- Use the command
- Mac: see instructions here
Installation can be verified using the below instructions.
Verify JRE Installation
C:\>java -version java version <your-java-version> ...
If you successfully get the displayed output, on executing
java -version, then JRE is successfully installed on your machine.
Verify Compiler Installation
Now to verify that Java compiler has also been set up properly, execute the below command
C:\>javac -version java <your-java-version>
If you successfully get the displayed output, then be assured that Java setup is complete on your machine. — ## Installing Library Source & Documentation
Library source code is downloaded as part of the JDK bundle, in
src.zip file, at JAVA_HOME. All we need to do is unpack the files to a src folder in JAVA_HOME, so follow the below steps (in a command line shell):
C:\> cd %JAVA_HOME%