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.
- Get Java SE (Standard Edition ) from this link that is something like jdk-8u211-windows-x64.exe. You will get several versions of java.
- Click on the .exe file and follow the procedure to install it.
- 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.
- Right-click on ‘My Computer‘ and select ‘Properties‘.
- Then click -> ‘Advances system settings -> Environment variables‘ button under the ‘Advanced‘ tab.
- Now, Under System variables find ‘Path‘ and press the edit button.
- 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
- Then do the same for jre.
- Then press OK and you are good to go.
Set path for MAC OS X
- Open Terminal
- Confirm you have JDK by typing “which java”. It should show something like /usr/bin/java.
- 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
- Set JAVA_HOME using this command in Terminal: export JAVA_HOME=/Library/Java/Home
- echo $JAVA_HOME on Terminal to confirm the path
- 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:
- 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
- Change to your home directory.
- Open the .bashrc file.
- 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
- Save the file and exit.
- Use the source command to force Linux to reload the .bashrc file which normally is read only when you log in each time.
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.
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.
- Notepad – On the windows machine you can use notepad.
- NetBeans – This is the most used IDE that is open-source that you can download it from https://netbeans.org/
- 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.