Java – Environment Setup

Java – Environment Setup

We will be setting up the local environment for java development. We will follow the simplest way for that.

Local Environment like PC

I think your are willing to  java environment setup on your machine. To do that please follow these simple steps that are described below.

Download

  1. Get Java SE (Standard Edition ) from this link that is something like jdk-8u211-windows-x64.exe. You will get several versions of java.
  2. Click on the .exe file and follow the procedure to install it.
  3. After that we need to setup the path so that we can use it from the control panel as well.

Setting up the path

For windows users: If you have installed the jdk to  -> ‘c:\Program Files\java\jdk’ then follow the instructions below.

  1. Right-click on ‘My Computer‘ and select ‘Properties‘.
  2. Then click -> ‘Advances system settings -> Environment variables‘ button under the ‘Advanced‘ tab.
  3. Now, Under System variables find ‘Path‘  and press the edit button.
  4. Press new button and paste the sdk->bin folder path here. Like for mine, my path variable is -> C:\Program Files\Java\jdk1.8.0_201\bin
  5. Then do the same for jre.
  6. Then press OK and you are good to go.

Set path for MAC OS X

  1. Open Terminal
  2. Confirm you have JDK by typing “which java”. It should show something like /usr/bin/java.
  3. Check you have the needed version of Java, by typing “java -version”.
    • JAVA_HOME is essentially the full path of the directory that contains a sub-directory named bin which in turn contains the java.
    • For Mac OSX – it is /Library/Java/Home
  4. Set JAVA_HOME using this command in Terminal: export JAVA_HOME=/Library/Java/Home
  5. echo $JAVA_HOME on Terminal to confirm the path
  6. You should now be able to run your application

Note that this sets JAVA_HOME only for this session. If you want it to persist, you will have to add the command to your ~/.profile file.

Below are instructions on how to accomplish this instead:

  • Open up Terminal.app (Applications >> Utilities >> Terminal)
  • Type: emacs .profile
  • add this to the end of the .profile file:

JAVA_HOME=/Library/Java/Home
export JAVA_HOME;

  • Save and exit emacs (ctrl-x, ctrl-s; ctrl-x, ctrl-c)
  • Open a new Terminal window (cmd-n) and type: $JAVA_HOME/bin/java -version

If you see something like:
java version “1.5.0_16″
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)
Java HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)

Then you’ve successfully set your JAVA_HOME environment variable to the binary stored in /Library/Java/Home/bin/java.  Reference.

Set Path On Linux

  1. Change to your home directory. cd $HOME
  2. Open the .bashrc file.
  3. Add the following line to the file. Replace the JDK directory with the name of your java installation directory. export PATH=/usr/java/<JDK Directory>/bin:$PATH
  4. Save the file and exit.
  5. Use the source command to force Linux to reload the .bashrc file which normally is read only when you log in each time. source .bashrc

Note that if you wish to set the PATH for all users, you need to log in as root in the bash shell and perform the above steps on the .profilefile in the etc directory and not the .bashrcfile in the home directory. Reference.

Editors

So we have setup our environment and now it is time to jump in but where can we write  our programs.

Well for that we have so many options and choose from below.

  1. Notepad – On the windows machine you can use notepad.
  2. NetBeans  – This is the most used IDE that is open-source that you can download it from https://netbeans.org/
  3. Eclipse – A Java IDE developed by the eclipse open-source community and can be downloaded from https://www.eclipse.org/

I hope we are successfully done with the java environment setup. If there is any problem with the setup, please comment below. To know about java you can go visit the previous tutorial.

The next tutorial we will be learning about the  basic syntax of java.

This Post Has 4 Comments

Leave a Reply

Close Menu