How to Set Up a Java Programming Environment

Method 1 of 2:

On Windows 8/10

  1. Install the JDK from the Oracle website.
    1. You can find the download here: http://www.oracle.com/technetwork/java/javase/downloads/index.html
    2. Make sure to download the JDK.
  2. Identify the installation location of the JDK.
    1. It is usually a sub-folder within this path: C:Program FilesJava
  3. How to Set Up a Java Programming Environment Picture 1
    Edit the System Environment Variables.
    1. On the window that appears, click the "Environment Variables..." button.
  4. Create a new variable named JAVA_HOME, and set the installation location of the JDK as the value.
  5. Edit the PATH variable.
    1. Add a semicolon at the end.
    2. Add the JDK installation location with "bin" after the semicolon.
  6. Make sure to click "Okay" on all of the Environment Variables to save the new settings.
  7. Open up Command Prompt.
    1. Hold Win+R to open the "Run..." dialog.
    2. Enter cmd and hit Enter.
  8. Verify the Java compiler is recognized.
    1. Type javac -version and hit Enter.
    2. If you see the version of Java printed out, it worked! If you see that it's "not recognized", go back and check the previous steps for any errors.
  9. Run a Java program.
    1. Copy the Hello World program from Oracle's website and save it to a file: https://docs.oracle.com/javase/tutorial/getStarted/cupojava/win32.html
    2. In Command Prompt, navigate to where to saved the file.
      1. If you're not comfortable with command prompt, there are many tutorials to help.[1] Check out How to Change Directories in Command Prompt.
    3. Run javac HelloWorld.java(assuming your file is named HelloWorld.java) to compile your Java source file into a class file.
      1. If you see an error, you likely have a bug in your program or haven't navigated to where your file is located.
    4. Run java HelloWorld to run your compiled Java program.
Method 2 of 2:

On a Mac

  1. Install the JDK from the Oracle website.
    1. You can find the download here: http://www.oracle.com/technetwork/java/javase/downloads/index.html
    2. Make sure to download the JDK.
  2. Open the Terminal.
  3. Verify the Java compiler is recognized.
    1. Type javac -version and hit Enter.
    2. If you see the version of Java printed out, it worked! If you see that it's "not recognized", go back and check the previous steps for any errors.
  4. Run a Java program.
    1. Copy the Hello World program from Oracle's website and save it to a file: https://docs.oracle.com/javase/tutorial/getStarted/cupojava/win32.html
    2. Navigate to where you saved the program.
      1. If you're not familiar with how to navigate in Terminal, there are many tutorials to help.[2][3][4]
    3. Run javac HelloWorld.java (assuming your file is named HelloWorld.java) to compile your Java source file into a class file.
      1. If you see an error, you likely have a bug in your program or haven't navigated to where your file is located.
    4. Run java HelloWorld to run your compiled Java program.
5 ★ | 1 Vote

May be interested

  • How to Make a GUI Grid in JavaPhoto of How to Make a GUI Grid in Java
    the grid does nothing special at this stage, but with a little bit of research, you can add action listeners and a bit of logic to make a simple 2d game like tic-tac-toe, or more complicated ones like battleship. note: this article uses...
  • How to Enable JavaPhoto of How to Enable Java
    java is a programming language and platform commonly used in a number of websites and applications. when java is not enabled, you can experience difficulty with viewing or using certain websites and applications. to use java, you must have...
  • How to Get Rid of Java Update NotificationsPhoto of How to Get Rid of Java Update Notifications
    this wikihow teaches you how to prevent java from sending update notifications every time you log into your computer. open the java control panel. to do so:
  • How to Create a Java Class in Netbeans to Compute the Area of a Triangle Using Heron's FormulaPhoto of How to Create a Java Class in Netbeans to Compute the Area of a Triangle Using Heron's Formula
    this guide will walk you through the steps need to compute the area of a triangle using the heron's formula in netbeans. you may use any ide you like, but this tutorial will be using netbeans and oracle's java jdk 8u101. download and...
  • How to Get Input from a User in JavaPhoto of How to Get Input from a User in Java
    when programming in java or any other language, you will most likely need to use input information from a user. java provides many different methods for getting in user information, but the most common and perhaps easiest to implement...
  • How to Set Java HomePhoto of How to Set Java Home
    do you want to set java home? the variable java home, generally written as java_home, is set to the install path of java. learning how to set java_home in windows and linux isn't hard to do. assuming that the path for the java development...