wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, volunteer authors worked to edit and improve it over time.
The wikiHow Tech Team also followed the article's instructions and verified that they work.
This article has been viewed 29,311 times.
Learn more...
Java is a popular and long-standing programming language, used by large and small, new and old companies alike. Setting up your computer to run Java for the first time can be a mild hassle. This wikiHow will detail how to configure the Java Development Kit (JDK) on your computer to prepare you for running Java. Setting up an integrated development environment (IDE) like Eclipse or IntelliJ is not included within the scope of this article.
Steps
On Windows 8/10
-
1Install the JDK from the Oracle website.
- You can find the download here: http://www.oracle.com/technetwork/java/javase/downloads/index.html
- Make sure to download the JDK.
-
2Identify the installation location of the JDK.
- It is usually a sub-folder within this path: C:\Program Files\Java
Advertisement -
3Edit the System Environment Variables.
- On the window that appears, click the "Environment Variables..." button.
-
4Create a new variable named JAVA_HOME, and set the installation location of the JDK as the value.
-
5Edit the PATH variable.
- Add a semicolon at the end.
- Add the JDK installation location with "\bin" after the semicolon.
-
6Make sure to click "Okay" on all of the Environment Variables to save the new settings.
-
7Open up Command Prompt.
- Hold ⊞ Win+R to open the "Run..." dialog.
- Enter cmd and hit ↵ Enter.
-
8Verify the Java compiler is recognized.
- Type javac -version and hit ↵ Enter.
- 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.
-
9Run a Java program.
- 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
- In Command Prompt, navigate to where to saved the file.
- If you're not comfortable with command prompt, there are many tutorials to help.[1] Check out How to Change Directories in Command Prompt.
- Run javac HelloWorld.java(assuming your file is named HelloWorld.java) to compile your Java source file into a class file.
- If you see an error, you likely have a bug in your program or haven't navigated to where your file is located.
- Run java HelloWorld to run your compiled Java program.
On a Mac
-
1Install the JDK from the Oracle website.
- You can find the download here: http://www.oracle.com/technetwork/java/javase/downloads/index.html
- Make sure to download the JDK.
-
2
-
3Verify the Java compiler is recognized.
- Type javac -version and hit ↵ Enter.
- 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.
-
4Run a Java program.
- 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
- Navigate to where you saved the program.
- Run javac HelloWorld.java (assuming your file is named HelloWorld.java) to compile your Java source file into a class file.
- If you see an error, you likely have a bug in your program or haven't navigated to where your file is located.
- Run java HelloWorld to run your compiled Java program.
Warnings
- If you're not familiar with system environment variables, do not delete anything in the related dialogs. If you delete the wrong variable, you can render your system unusable.⧼thumbs_response⧽
References
- ↑ https://www.digitalcitizen.life/command-prompt-how-use-basic-commands
- ↑ https://www.macworld.com/article/2042378/master-the-command-line-navigating-files-and-folders.html
- ↑ https://computers.tutsplus.com/tutorials/navigating-the-terminal-a-gentle-introduction--mac-3855
- ↑ https://macpaw.com/how-to/use-terminal-on-mac
- https://www.java.com/en/download/help/path.xml