Setting Up Java Part 2
Published: 2020-10-21 18:58:13

---
title: Setting Up Java Part 2
published: true
description: running our first program
tags: 
//cover_image: https://direct_url_to_image.jpg
---

> # Important!
> This tutorial is made for Windows 10

In [Part 1](https://smolnotes.netlify.app/posts/installingjavaasablindperson/) 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 <code>javac -version</code>. After, enter in <code>java -version</code>. 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](https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html) 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 <code>setx JAVA_HOME "PAST THE PATH HERE "</code>. In the next line, type <code>setx PATH "%PATH%;%JAVA_HOME%\bin";</code>. If you are stuck, refer to [this very useful tutorial](https://www.codejava.net/java-core/how-to-set-environment-variables-for-java-using-command-line). 

Now open a file in Notepad and  copy and past:

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

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 <code>cd PASTE PATH OF FILE</code>. Next type <code>javac HelloWorld.java</code>. This will compile the code (basically translating it from Java to a language the computer can understand). Follow this by typing <code>java HelloWorld</code>. 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](https://www.quora.com/What-is-difference-between-JDK-JRE-and-JVM) explains the difference between JVM are JRE.

[Here](https://www.infoworld.com/article/3304858/what-is-the-jre-introduction-to-the-java-runtime-environment.html) you can read a more in depth article explaining JRE.