- Download the JDK (Oracle JDK or OpenJDK, version 17 or later) and install it, e.g. in C:\Program Files\Java\jdk-21.
- Open Start → "Edit the system environment variables" → Environment Variables.
- PATH: edit Path → New → C:\Program Files\Java\jdk-21\bin (this lets you type javac and java anywhere).
- CLASSPATH (optional): New variable CLASSPATH = .; (the dot means "current folder").
- Open a new Command Prompt and check: javac -version and java -version.
- Save the program as Main.java, then run: javac Main.java and java Main
Output
Hello! Java is installed correctly. Java version : 21 Running from the command prompt.
public class Main
{
public static void main(String[] args)
{
System.out.println("Hello! Java is installed correctly.");
System.out.println("Java version : " + System.getProperty("java.specification.version"));
System.out.println("Running from the command prompt.");
}
}