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 8.
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.
For Windows(32 bit),you have to click second last link and for Windows(64 bit),you have to click last link as illustrated 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.
Click on Advanced System Setting option.You will see as illustrated below.
Now click on Environment Variables as highlighted in image.
- Now click on New tab under user variable.
Give the variable name of your choice (example:JAVA_HOME)
For variable value click on Browse Directory tab as illustrated and Copy the path of bin folder of Java.
- Now under Browse Directory go to PATH = C:\Program Files\Java\jdk\bin and click OK.
By default java is installed in Program Files or Program Files(x86) folder. In case, you have installed java at any other location,then select that path.
- Save the settings and you are done !! Now to check whether installation is done correctly, open command prompt and type java -version. You will see that java is running on your machine.
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.
Popular Java Editors/IDE :
- 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.