Skip to main

Warning! #


This tutorial is made for Windows 10

In Part 1 of this series, we modified our coding environment so we can start programming without straining our eyes; in this post, we will install Java and write our first program!

A program is a set of instructions that tells the computer what to do, like print “hello world!”. You might be wondering how do we boss the computer around? By talking to it! A programming language is a way of talking to the computer. It’s kind of like saying “please give me 50 strawberries” to the grocer. Computers talk in 0’s and 1’s though, and we don’t. There are many languages we can use to talk to computers however: python, javascript and java are just a few. This is like how there are many languages like Spanish, French and German, we can use to talk to each other. The java virtual machine (jvm) lets us use java to talk to any computer instead of using 1’s and 0’s, this is why it’s considered an interpreter. The JVM is called “virtual” because it’s not a physical thing. We need something to actually commence the talking though, that’s where the Java Runtime Enviroment (jre) comes in. The JRE starts the action. Now we need something that let’s us talk in Java: that is the Java Developer Kit (jdk). The Java developer kit includes the jvm, jre and a host of other tools that will let us start writing programs.

Before installing the JDK, let’s see if you already have the necessary tools.

In the command prompt type javac -version. After, enter in java -version. If both return errors that’s ok!

Assuming you don’t have the JDK installed on your computer, we’re going to do that next. Head over here to install the JDK. You can find out if your computer is a 64 bit or 32 bit by going to
About Your PC. You will need to set its path after installation if you are on windows. Find where your computer installed the JDK, copy its path (this can be done by right clicking on the file). In the command promt type setx JAVA_HOME "PAST THE PATH HERE ". In the next line, type setx PATH “%PATH%;%JAVA_HOME%\bin”;. If you are stuck, refer to this very useful tutorial.

Now open a file in Notepad and copy and past:


class HelloWorld {
    public static void main(String[] args){
        System.out.println("Hello World");
    }
}

Save this file as HelloWorld.java. It is important that the file name matches the class name. Copy the path of the folder the file is saved in. In the command promt type cd PASTE PATH OF FILE. Next type javac HelloWorld.java. This will compile the code (basically translating it from Java to a language the computer can understand). Follow this by typing java HelloWorld. Now your program will run. You should see printed out: “Hello World!”.

Congratulations!! A lot was covered in this post and you just wrote your first program! It’s okay if you don’t know what it is you just did or what any of it means. You’ll get there.


I most likely did a poor job explaining. This article explains the difference between JVM are JRE.

Here you can read a more in depth article explaining JRE.