Setting up the environment in Java

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

  1. JDK(Java Development Kit) : JDK is intended for software developers and includes development tools such as the Java compiler, Javadoc, Jar, and a debugger.
  2. 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.
  3. 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

  1. 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.
    Capture
  2. 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.
  3. Go to Control Panel -> System and Security -> System.
    Under Advanced System Setting option click on Environment Variables as highlighted below.
    Capture
  4. 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.
    java environment setuo

  5. 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.

    Java environment setup

  6. Click on OK, 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.
  7. 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.

  1. Go to Application -> Accessories -> Terminal.
  2. Type command as below..
    sudo apt-get install openjdk-8-jdk
    
  3. 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
    
  4. 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
    
  5. 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.
  6. 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 contribute@geeksforgeeks.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.

GATE CS Corner    Company Wise Coding Practice

Recommended Posts:







Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.