Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented etc.
Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of computer architecture.The latest version is Java 15.
Below are the environment settings for both Linux and Windows. JVM, JRE and JDK all three are platform dependent because configuration of each Operating System is different. But, Java is platform independent.
There are few things which must be clear before setting up the environment
- JDK(Java Development Kit) : JDK is intended for software developers and includes development tools such as the Java compiler, Javadoc, Jar, and a debugger.
- JRE(Java Runtime Environment) : JRE contains the parts of the Java libraries required to run Java programs and is intended for end users. JRE can be view as a subset of JDK.
- JVM: JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed. JVMs are available for many hardware and software platforms.
Steps for Setting up Java Environment for Windows
- Java8 JDK is available at Download Java 8.
Click second last link for Windows(32 bit) and last link for Windows(64 bit) as highlighted below.
- After download, run the .exe file and follow the instructions to install Java on your machine. Once you installed Java on your machine, you have to setup environment variable.
- Go to Control Panel -> System and Security -> System.
Under Advanced System Setting option click on Environment Variables as highlighted below.
- Now, you have to alter the “Path” variable under System variables so that it also contains the path to the Java environment. Select the “Path” variable and click on Edit button as highlighted below.
- You will see list of different paths, click on New button and then add path where java is installed. By default, java is installed in “C:\Program Files\Java\jdk\bin” folder OR “C:\Program Files(x86)\Java\jdk\bin”. In case, you have installed java at any other location,then add that path.
- Click on OK, Save the settings and you are done !! Now to check whether installation is done correctly, open command prompt and type javac -version. You will see that java is running on your machine.
- In order to make sure whether compiler is setup, type javac in command prompt. You will see a list related to javac.
Steps for Linux
In linux, there are several ways to install java. But we will refer to simplest and easy way to install java using terminal. For linux we will install OpenJDK. OpenJDK is a free and open source implementation of the Java programming language.
- Go to Application -> Accessories -> Terminal.
- Type command as below..
sudo apt-get install openjdk-8-jdk
- For “JAVA_HOME” (Environment Variable) type command as shown below, in “Terminal” using your installation path…(Note: the default path is as shown, but if you have install OpenJDK at other location then set that path.)
export JAVA_HOME = /usr/lib/jvm/java-8-openjdk
- For “PATH” (Environment Value) type command as shown below, in “Terminal” using your installation path…Note: the default path is as shown, but if you have install OpenJDK at other location then set that path.)
export PATH = $PATH:/usr/lib/jvm/java-8-openjdk/bin
- You are done !! Now to check whether installation is done correctly, type java -version in the Terminal.You will see that java is running on your machine.
- Notepad/gedit : They are simple text-editor for writing java programs. Notepad is available on Windows and gedit is available on Linux.
- Eclipse IDE : It is most widely used IDE(Integrated Development Environment) for developing softwares in java. You can download Eclipse from here.
Related Article: How to run java class file which is in different directory?
This article is contributed by Gaurav Miglani. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.