- Compile and execute a Java program
- Create a new class including a main method
- Bonus
- Learn how to set up your environment by installing the JDK (Java Development Kit) and
Notepad++ on your machine
- Begin by creating an Oracle account
- Download the Java SE Development Kit 8u261 installer
- Execute the installer
- Accept all the default settings
- Click "Next" until installation is complete
- Navigate to your system environment variables
- Control Panel > System and Security > System > Advanced system settings > Environment
Variables
- You may also search for "Environment Variables" in the Windows search bar and select the
"Edit the
system environment variables" option
- Under the "System Variables" table, select the "Path" variable and click "Edit"
- Click "New" and enter the path to the bin folder of your JDK installation
- The default path to the JDK bin folder is: C:\Program Files\Java\jdk1.8.0_261\bin
- Press "Enter" and click "Ok"
- Open Command Prompt
- On Windows 10, do this by typing "cmd" in the Windows Search Bar and pressing "Enter"
- In the Command Prompt, type "java -version"
- This should display information pertaining to the version of Java installed on your computer
- Notepad++ is a free text editor
- Later on you will learn about other programs that can better help you write code
- However, we believe that it is important to learn how to do things yourself when you are
starting out.
- Download the Notepad++ installer
- Execute the installer
- Accept all the default settings
Note: Notepad++ is not available for mac, however, any text editor will work as a replacement.
- Open Notepad++
- Type the following text into your editor
- The case and spelling is very important!
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
- Under the "File" tab, select "Save As..."
- Save this file on your desktop as "HelloWorld.java"
- This must be the name of the file!
- Open Command Prompt
- Confirm that you have correctly installed Java by entering the command "java -version"
- This command should display information based on the version of Java installed on your machine
- Change directories to the Desktop by entering the command "cd Desktop"
- Compile the program by entering the command "javac HelloWorld.java"
- Notice that a new file is created
- Execute the program by entering the command "java HelloWorld"