Configuring Environment Variables

If you are using a Java version that is older than Java 15 (e.g. Java 14 or earlier) then you'll need to set up some system environment variables. Perform the steps below just after you've installed Java, before you download and install your development environment.

Set Up Environment Variables

The editor you're going to use (we'll install this in the next step) needs to know where the /bin directory of your Java installation is. That /bin directory contains the compiler program and the interpreter program, both of which are needed by your editor to compile and run Java programs. We must set up environment variables on your system that contains the location of the /bin directory. Your editor can then read those variables when it needs to know where the compiler and interpreter are.

  1. First, you must get the exact location of the /bin directory in your Java installation directory. Use your preferred file browsing utility to browse to your computer's C:\drive (e.g. it's usually listed as something like "Local Disk (C:)" under "This PC"). Next, browse to the directories Program Files > Java > jdk-14.0.x (the 14.0.x might be a different value, depending on what version of Java you're dealing with). Inside the JDK directory, you should see the /bin directory. Go into the /bin directory but don't touch any of the files in that directory.
    LEFT: shows the navigation to my JDK directory on my home computer: Local Disk C to Program Files to Java to jdk-13.0.1; RIGHT: shows the /bin directory highlighted with the other directories listed also (conf, include, jmods, etc)
    Browse to the Java directory in your computer's Program Files and then go into the jdk-XX.x.x directory.
  2. Move your mouse up to the address bar and click in any of the white space after the path listed there.
    top part of the previous image focusing on the address bar that has This PC > Local Disk C > Program Files > Java > jdk-13.0.1 > and some blank space after that
    Click in the blank space area in the address bar, after the location.
  3. Once you click inside the address bar, the complete path to the /bin directory will appear and become highlighted. Press Ctrl-C on your keyboard to copy that selected text to the Windows clipboard.
    same part of the previous image, but this time the address bar shows the location as text and it has been selected C:\Program Files\Java\jdk-13.0.1
    Select the text in the address bar if it's not already selected and then copy it e.g. Ctrl-C
  4. Keep the copied text in your clipboard - don't copy anything else until you've pasted that text elsewhere. If you prefer, you can open any text editor, word processor, or sticky note app and paste the text there in case you lose it.
  5. Now we need to find the PATH environment variable and add the location of the JDK's /bin directory to it.
  6. Use your Windows search to search for system environment variables. You should see a matching item called "Edit the System Environment Variables" and "Control Panel" in smaller letters below it. Click the item "Edit the System Environment Variables".
    the search value entered in the search bar, shows Edit the system environment variables as the top match
    Search for "system environment variables" and then select the option "Edit the system environment variables"
  7. A dialog box will open called "System Properties", and you should already be on the "Advanced" tab automatically. You'll see three "Settings" button, and below those, a button that says "Environment Variables". Click the Environment Variables button.
    system properties dialog: 3 areas, all with own Settings button, and Environment Variables button below the 3 areas; buttons Ok, Cancel, disabled Apply at bottom of dialog
    Click the Environment Variables button.
  8. The Environment Variables window appears. It has an area on top where you can edit/create environment variables for your current account, and an area on the bottom half that allows you to edit/create environment variables for the whole system. We want to add an environment variable for the whole system that tells applications where Java is located on the computer. Make sure you're working in the bottom half of this window.
    people who don't read will screw this up: two halves of screen (top and bottom) and each half shows a list of environment variables (top half for user, bottom half for system); 
                                 each half has the same set of buttons (new, edit, delete);
                                 work in the bottom half of the dialog with the heading System Variables, ignore the top half
    ALWAYS work in the bottom half of the Environment Variables window!! Ignore the top half.
  9. In the bottom area of the window, click the "NEW" button.
    make sure you click the button(s) in the bottom half (System Variables)
    In the bottom half of the window, click the NEW button.
  10. You'll be presented with a small dialog that asks for the environment variable name and the environment variable value. Enter the variable name as JAVA_HOME
    That's the word "JAVA" in all upper-case, followed by an underscore, followed by the word "HOME" in all uppercase. Do not use lowercase and do not add any spaces. It is important that you type the name exactly as shown.
  11. For the variable value, paste the path to the JDK that you copied earlier, for example, C:\Program Files\Java\jdk-XX.x.x (where XX.x.x is the version of Java you have).
    Edit System Variable dialog: a field Variable Name and a second field Variable Value; buttons Browse Directory.. Browse File on the left; buttons Ok, Cancel on the right
    Enter the variable name and value as described.
  12. When you're finished, double-check that your 2 inputs are correct. Then click the OK button.
  13. Once you're back in the Environment Variables window, you should see your new JAVA_HOME environment variable in the list in the bottom half of the screen. If you don't see it there (check the screen shot and compare), go back and double-check that you've read and followed the instructions correctly.
    environment variables window again, this time showing the new JAVA_HOME variale in the list of System Variables
    You should see your new JAVA_HOME environment variable in the list.
  14. Next, we need to add our new JAVA_HOME variable to the system's PATH variable. The PATH variable contains a list of paths or locations of different files and programs. it might appear as "Path" or "PATH", but to make this easier to read I'll use "PATH". This variable is used by your computer: when you run a program, the computer will search all the locations in the PATH so it knows where to find the files it needs. It's a little bit like an address book or contacts list for programs on your computer: when an application wants to find a program, it looks inside any location that's listed in the PATH variable. Some programs won't work if they don't know where certain files are located. For example, when you want to compile and run Java programs, your editor will need to know where the compiler program and interpreter program are located, so it will check the system's PATH variable.
  15. Locate the PATH variable in the list in the bottom half of the window and select it. Then click the EDIT button.
    in the list of system variables in the bottom half, look for the one called path; they're sorted alphabetically; then click the Edit button in the bottom half
    In the bottom half of the screen, select the PATH variable and click the EDIT button.
  16. You should now see the "Edit Environment Variable" dialog box. It will most likely contain a list of different paths and locations, and many will include % symbols in them. Click the NEW button. A small area will open up after the last list item where you can type. Enter
    %JAVA_HOME%\bin
    It's important that you type this exactly as shown here, with no spaces, and with the right case (JAVA_HOME in uppercase and bin in lowercase). When you've finished typing, check that you've typed the value correctly. Then press the ENTER key on your keyboard. If you need to edit the value, just click it or select it and click the EDIT button.
    edit envionment variable window: this could come in two forms - one has 2 fields with Path in the first field and a lot of junk in the second field, but more likely you have a long list of stuff and a list of buttons on the right side (new, edit, browse, delete, move up, move down, edit text); the surrounding instructions in these notes should tell you what to do here
    Add an entry for %JAVA_HOME%\bin to the existing set of paths.
    NOTE: if you don't see the same screen as above, you might instead just see a field with a very long string of characters. Put your cursor in the field for the variable value and go to the very end. Add a semi-colon and then the java home bin directory e.g. ;%JAVA_HOME%\bin
  17. When you've finished editing the PATH variable, click the OK button to save your changes.
  18. That's all you need to do in this window, so now make sure you click the OK button in the Environment Variables window.
    the environment variables window again showing the edited Path variable (probably can't see the actual part you edited but that's normal); the buttons at the very bottom of the whole dialog are Ok and Cancel
    Click the OK button to save all your changes
  19. Your changes won't work on your system until you also close the System Properties dialog. Return to the System Properties dialog and click the OK button.
    back to the system properties window: go to the buttons at the very bottom (ok, cancel, apply (probably disabled))
    Click the OK button to save your system property settings.

That takes care of installing and setting up Java. Next, you need to install and setup your Java editor.