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.
    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.
    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.
    Click on Advanced System Setting option.You will see as illustrated below.
    Now click on Environment Variables as highlighted in image.
    Capture
  4. 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.
    Capture
  5. 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.
    Capture
  6. 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.

  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.

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





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