Java Install

Downloading the JDK installer

https://www.oracle.com/java/technologies/downloads/

Java 17

Run the JDK Installer.
You can complete the installation simply by clicking the Next button.
The installed JDK directory is C:\Program Files\Java\jdk-<version>.

Environment Variable

Click Start, then Control Panel, then System.

System Properties

Select the Advanced tab, then Click the Environment Variables button.

System Properties Advanced

Click the New button in User Variables.

Environment Variables
User variables for John
Variable Value
   
   
   
System variables
Variable Value
   
   
   

Creates a new environment variable named JAVA_HOME in User Variables.
The value of JAVA_HOME is the installation directory of the JDK.
To obtain the correct value, use Windows Explorer.

New User Variable
Variable name:
Variable value:

Click the New button in User Variables again.
Creates a new environment variable named Path in User Variables.
The value of Path is %JAVA_HOME%\bin. (If the Path variable already exists, add the bin directory of the JDK to the Path)

New User Variable
Variable name:
Variable value:
Path

OS adds the user Path's value to the xystem Path.
OS looks for executables in the system variable Path.

By adding the JDK's bin directory to the Path variable, you can run Java executables (javac.exe, java.exe, jar.exe, etc.) from any directory.

C:\ Command Prompt
C:\Users\John>javac Test.java

If you do not set the Path variable, you need to move to the directory where the executable program is located, such as:

C:\ Command Prompt
C:\Program Files\Java\jdk-17.0.2\bin>javac C:\Users\John\Test.java

Run the following command in the command prompt to confirm the Path variable.

C:\ Command Prompt
C:\Users\John>echo %PATH%
The Semi-colon separates the Path variable's values in Windows.
The colon separates the PATH variable's values in Unix and Linux.

Test

Run the following command:

C:\ Command Prompt
C:\Users\John> notepad Test.java

After saving the file, type:

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

Compile and run:

C:\ Command Prompt
C:\Users\John> javac Test.java

C:\Users\John> java Test
Hello World!
javac' is not recognized as an internal or external command, operable program or batch file.
If the above error occurs when running javac Test.java, execute "echo %PATH%" and check if the value of the Path variable includes the bin directory of the JDK.
Exception in thread "main" java.lang.NoClassDefFoundError: Test

The above error occurs when Java cannot find the Test.class file. You may get this error when you run "java Test" from a directory that doesn't have a Test class file. To run from a directory where the class file does not exist, use the -cp option of java.exe.

C:\ Command Prompt
C:\Program Files>java -cp C:\Users\John Test

"C:\Users\John" is the directory where Java class files locate.
"Test" is the Java class file to run. You must remove the extension of the file.

Editor

Until Package and Modifiers, it is better to use a simple editor such as editPlus and Notepad++.
After you finish the Package and Modifiers, use Eclipse.