In this class we will use:
Notepad ++
We will use the free, offline program "Notepad ++" to type our code. This program organizes your code as would Repl.it or Code Pretty, but does not write the basic code for you, which is something a program like Eclipse would do for you. More on this program below.
Java Development Kit (JDK)
The Java Development Kit is free and available online for any operating system. It takes the universal Java programming code (source code) and compiles it to machine bite-code that runs on your specific machine type. Files ending in ".java" are universal Java programming code and could be emailed to friends using any operating system. Once you compile them they become files ending in ".class". These are type specific and could only be run on a similar machine (aka compiling Java on an Apple would not then be able to run *.class on Windows).
Command Interpreter (cmd)
The Windows command interpreter takes in text-based commands and executes them. This is where we will compile and run our Java Source Code files.
Installing & Using Notepad++
Visit the website - https://notepad-plus-plus.org/
Download the appropriate version for your operating system.
Run the installer and finish.
Open Notepad++
Create a new file,type a few letters in it, then click "File --> Save As ..."
Type in a file name. Under file name, click on the drop down menu next to "Save as type:" and select "Java source file (*.java)"
On your desktop, create a folder titled "Workspace"
Place your saved Java Source File into this folder.
Double click on this file. You will get an error that says "Windows can't open this file:". Choose the second option that reads "Select a program from a list ..." and then click OK.
Now make sure that the option on the bottom left is check that reads "Always use the selected program ...". Then click on the "Browse..." button and find Notepad++. The default Windows install directory is "C:\Program Files\Notepad++\".
Now your Notepad++ should be ready to use, and all your .java files should default open in Notepad++.
Installing the Java Development Kit & Setting up PATH
Visit the website - LINK (If this link doesn't work, just Google "JDK" and click on the first link)
Click the link to download the JDK
Agree to the terms, and download the JDK for your correct operating system.
Run the installer and keep all settings as their default.
Now locate the "bin" folder that has the executable Java compilers and key programs. The default directory is "C:\Program Files\Java\jdk1.8.0_121\bin" where the "121" is the current build/version of JDK8. Your build number might be different at your time of install so check this.
Now set up your universal "PATH" environmental variable for windows so you don't always need to type the full location of your Java Compiler such as "C:\Program Files\Java\jdk1.8.0_121\bin\javac.exe" and instead you can just type "javac" to run it.
Note - These directions are for Windows 7 and 10. Other operating systems have a different way to do this.
Open your start menu and right click on "Computer"
Click on "Advanced System Settings"
Go to the "Advanced" tab and click on "Environment Variables"
If you do not have a variable named "PATH" click new. For variable name type "PATH" and for variable value enter the path you found in step 5 similar to "C:\Program Files\Java\jdk1.8.0_121\bin"
If you already have a PATH variable, do not delete it or type over it. Instead, click "Edit". At the end of the current variable value, type a semicolon and add your directory path after the current value. Such as "first_value_that_way_already_there; C:\Program Files\Java\jdk1.8.0_121\bin"
To test if everything is installed correctly, click on the Start Menu at the bottom of your screen and enter "cmd". This opens your Command Interpreter. Type in "javac" and hit enter. You should see something like:
Setup Correctly
Not Setup Correctly
Command Interpreter (cmd)
A command line interpreter takes in text-base commands and executes them to the operating system. It literally translates commands.
You open this by clicking on the Start Menu, typing "cmd" and hitting enter. By default, you start in the directory "C:\users\yourUserName\".
The main commands we will be using are:
Testing Out Your First Program
Open Notepad++ and paste the code below in:
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); }}
Save this as a Java Source Code file (*.java). I would name it "HelloWorld.java"
Open Command Interpreter (cmd) from the Start Menu.
Navigate to the correct folder. If you have your work in the "Workspace" folder on the desktop, most people will usually enter "cd Desktop", then cd "Workspace".
Type "javac FileName.java" or in our example case it would be "javac HelloWorld.java"
Type "java FileName" or in our example case it would be "java HelloWorld"
You should see "Hello World!" in all its glory. You just compiled your first Java program! Whoot!