Setting up environment for Java
We have now understand what is Java, it’s features and how it is working internally. Now, it is time to setup your machine to write and run java programs. In this tutorial, I will explain each and every step in order to setup your local environment for Java.
So let’s get started.
Step 1 : Download Java
First you need to download Java which is basically (JDK – Java Development Kit) from official website of Oracle Download Java Development Kit version 1.7
Download as per your Operating system like Unix, Solaris, Windows and according to the platform like 64 bit or 32 bit machine.
Step 2 : Install JDK on your machine
Next step is to install Java on your machine. You just need to follow the instructions while installing the jdk on your system. Installation may be different on different operating system.
Step 3 : Set path for the Java tool
After you have successfully installed Java on your machine. You need to set path of the Java tool in your system environment variable. After that you will be able to execute programs.
Basically all the tools required to run a java program resides inside jdk/bin folder. So we need to set path up to this location.
There are two ways to execute your program. Either you place your class files inside jdk/bin folder and execute. Or you need to tell the system from where to pick java tools.
There are two ways to set path.
Temporary – temporary path exist till the console is open.
Permanent – once set, you can run your program from any location.
How to set temporary path in Windows
You can run below command to set temporary path in command prompt :
set path = location_of_jdk_folder\jdk\bin
How to set path permanently in Windows Machine
Follow the below steps in order to set path in windows machine :
Click on Start button -> Right Click on My Computer -> Click on properties
On left side click on -> Advanced System Settings
System Properties pop up screen will open, then click -> Environment Variables under Advanced Tab
Environment Variables pop up screen will open, then you will see User variables list and system variables list.
Find “path” variable under system variable list and double click as below :
Then go to Variable Value and reach to the end of the value and paste the path as below
For example : C:\Program Files\Java\jdk1.7.0_71\bin
Click ok, ok and ok.
How to set path on Ubuntu/Linux Machine
JAVA_HOME environment variable, do the following:
- Launch Terminal by pressing Ctrl+Alt+T on your keyboard.
- Enter the following command:
gksudo gedit /etc/environment
- Depending on where you installed your Java, you will need to provide the full path. For this example, I installed Oracle JDK 7 in the
Scroll to the end of the file and enter the following:
- Save your file and exit gedit.
- Lastly, reload the system PATH with the following command:
How to set path in Mac Machine
Please follow the below instructions in order to set path on Mac machine.
create the bash_profile:
$ vim ~/.bash_profile
add this to the file:
execute the source command
$ source ~/.bash_profile
$ echo $JAVA_HOME /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home