Install Java in Windows 10

This article will run through the installation of Java JDK, and the creation of the traditional “Hello World” program in Java. These steps are for Windows 10 Pro 64-bit.

Install Java JDK

  1. Download the latest Jave SE JDK from Oracle. I’m using version jdk-8u121-windows-x64.

    Windows: This PC

  2. Run the installation. You can accept all the defaults, or review them and change as needed. I installed to a custom directory C:\Dev\Java\.

  3. Now we’ll want to add the java directory to our PATH variable. Launch This PC and click System Properties

    Windows: This PC

  4. Click Adanced System settings

    Windows: This PC

  5. In the System Properties window on the Advanced tab click the Environmental Variables… button

  6. In the Environmental Variables window select the Path variable and click Edit

    Windows: This PC

  7. Click New and enter the path to your Java JDK bin directory. For me this was C:\Dev\Java\jdk1.8.0_121\bin. Click OK

  8. Click OK again to close the Environmental Variables window, and OK again to close the System Properties window.

  9. Launch a command prompt and type java -version to make sure the new path variable works.

    >java -version

    You should see something like the below output:

    java version "1.8.0_121"
    Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

Hello World in Java

  1. Create a new directory to store your code in.

    mkdir tutorials
  2. Launch your favourite text editor or IDE and create a new file

  3. Type the following:

    public class HelloWorld {
        public static void main (String[] args) {
            System.out.println("Hello World of Java");
  4. Save the changes and go back to the command prompt. Ensure you are running in the same directory as the file is saved.

    cd tutorials
  5. Compile the program:

  6. If the code compiles succesfully it will create a new file HelloWorld.class. Run the program:

    java HelloWorld

    The console should print back our message:

    Hello World of Java

Note that the file name matches the class declaration on line 1 of our code: public class HelloWorld {....

If the two didn’t match we’d see an error like this:

>javac error: class HelloWorld is public, should be declared in a file named
public class HelloWorld {
1 error