This tutorial introduces Java and goes over the steps you need to follow to program Java on your computer. When we get to the programming part, I’m going to assume you’ve already been through the Processing tutorials. If you haven’t done them yet, go do them before moving on to Java!
Since you’ll be writing code, you need to download the Java Development Kit, aka the JDK. Go here and find the download button that says JDK (not JRE) and click that. That takes you to a page containing OS-specific download files. Download the one for your computer!
When the download completes, run the installer. The default settings should be fine. Remember where the installer puts Java- you’ll need that location in the next step!
PATH
is an environment variable that tells your computer where programs are located. We need to make sure that Java is on your PATH
.
Here are instructions for setting the PATH
on different operating systems.
On Windows 10, you can open the start menu and just type “path” which will show you an option for editing the system environment variables. Click that, which opens the System Properties dialog:
On that screen, click the “Environment Variables…” button, which opens up the Environment Variables dialog:
On that screen, find a variable called PATH
, select it, and click the Edit...
button.
Finally, on that screen, click the New
button and then paste the path the installer put Java. It’s usually something like C:\Program Files\Java\jdk1.8.0_121\bin
, but with different numbers depending on the latest version of Java. Note that the path ends in a bin
folder!
Press OK
in all the dialogs to accept your changes.
The command prompt is a text-based interface that lets you interact with the computer without any windows. It’s how a lot of coding tools are run, and it’s how we’re going to work with Java for now.
To open the command prompt, go to the start menu and then type “command” until you see a shortcut that says Command Prompt. Click that to open the command prompt, which looks like this:
You can use the command prompt by typing commands and pressing the enter key. Try these commands:
dir
lists everything in the current directory. Type dir
and press enter, and you should see a list of files.
cd
changes directories. Try to cd
into one of the directories listed by the dir
command. For example, to cd
to my desktop I would type cd desktop
and then press enter. If you want to go up a level, type cd ..
and press enter.
mkdir
creates a directory. Type mkdir HelloJava
to create a directory named HelloJava
. Then cd
into it by typing cd HelloJava
and pressing enter.
javac
runs the Java compiler. We’ll talk more about this in the next tutorial, but for now type javac -version
and hit enter. That should print out the version of Java you just installed. If you get an error here, make sure you’ve set your PATH
correctly!
java
runs Java programs. We’ll also talk more about this in the next tutorial, but for now type java -version
and hit enter. That should print out the version of Java you just installed. If you get an error here, make sure you’ve set your PATH
correctly!
PATH
variable is.Install and run Java.
Happy Coding is a community of folks just like you learning about coding.
Do you have a comment or question? Post it here!
Comments are powered by the Happy Coding forum. This page has a corresponding forum post, and replies to that post show up as comments here. Click the button above to go to the forum to post a comment!