Java is the bread and butter of programming world. It is a class and object-based language which runs on Java Virtual Machine (JVM). You will need JVM, JRE, and JDK on the basis of the operating system you are using. However, Java is very much platform independent. By reading this article you will learn more about Java and how to setup environment in Java for Windows, Linux, and macOS.
Things You Need to Learn Before Setting Up Environment in Java
You will need to look and learn few things if you want to correctly setup environment in Java for different operating systems. The very first is Java Development Kit or JDK. Working with software development requires different set of tools such as Java compiler, Javadoc, and a debugger. These tools will help you immensely if you are a software developer.
The second is Java Runtime Environment or JRE in short form. Programs made by Java need some special Java libraries to run it and JRE has them all. Normal devs do not have to worry about it during development as most end-users need it. You can also refer JRE as the subset of JDK.
And the last one is Java Virtual Machine also known as JVM. In very simple terms, it simulates a runtime environment with all the specifications needed by Java bytecode to run. Also, most of the hardware and software platform supports it.
Steps to Setup Environment in Java for Windows, Linux, and macOS
For Windows
- Move to download website of Java8 JDK. Make sure the webpage is real and official.
- You now need to make a selection between (32-bits) and (64-bits).
- Before the downloading starts, you will see a prompt of its terms and conditions.
- Read and check the box before it.
- Now, you will have to click the box “download JDK windows 64.exe”.
- Wait for the download to finish and you will have to open the “exe” installer file.
- Follow all the steps you find in the installer and complete the whole process.
- Once done, go to your “Control Panel” and look for “System and Security”.
- After that, you will have to click on “Settings” and then tap on “Environmental Variable” box.
- You now search for the “PATH” in upper white box. Then, tap on “Edit” box.
- From the right side, click on “New” button.
- Now, go to Java installed place on your hard drive.
- C:\Program Files\Java\jdk\bin is one example.
- Lastly, click on “OK” box to save the made changes to the setting.
You now want to check if you have done all the steps correctly then open “Command Prompt” window. Type “javac –version” and wait for the results to popup. This will show if you have Java active and running on your device or not.
For Linux
Several methods are available to install and setup Java on Linux. However, here is the very simple steps which only need terminal. Before we do that, we need to have openJDK on the OS. Here are the needed instructions:
- Firstly, access “Accessories” in “Application”.
- You can now open “Terminal” from here.
- Enter this code line in it.
- “sudo apt-get install openjdk-8-jdk
- For “Java Home” which is “Environment Variable” enter this code line.
- export JAVA_HOME = /usr/lib/jvm/java-8-openjdk”
- This code line will work only when you have use default install location.
- If not then you will have to switch the location to where it is available.
- Now, for “PATH” “Environmental Variable” type this code line.
- “export PATH = $PATH:/usr/lib/jvm/java-8-openjdk/bin”
- That was the last step. You are now all setup and ready to go.
For macOS
- CMD and SHIFT keys will open “Terminal” in macOS. Or just run it from app folder.
- First of all, you will need to run some code line to configure.
- “java –version
- javac –version”
- This will let you know that JDK will work or if it is available on your system computer.
- Setup the environment in your Shell Profile.
- ~/.bashrc, ~/.zshrc or ~/.profile are some examples.
- After that do these code lines.
- export JAVA_HOME=/path/to/your/jdk
- export PATH=$PATH:$JAVA_HOME/bin
- Make sure to switch /path/to/your/jdk to the location where it is available.
- Now, apply these changes by running source ~/.bashrc code line in current terminal.
- To check whether it will work and you have done your part right, run this code line.
- java –version
- Lastly, if you see version of Java as a result then everything is setup and good to go.
Conclusion
Java is one of the most popular programming languages in the world and for many reasons. Eventhough, it is universally compatible with almost all platform and operating system you will have to set it up according to your personal work case. Also, there are certain things you will have to learn first in order to setup environment in Java correctly. In this article, we have discuss about the Java and how to setup environment in Java for Windows, Linux, and macOS.
Must Read: How To Use Windows Software on Mac?