Choose a JDK, not just a runtime
Java is the language. A Java Development Kit (JDK) provides the compiler and launcher needed to create and run programs. A runtime-only installation may run existing applications but does not give you javac for compiling source. For a new project, choose a maintained release supported by your course or dependencies. Java feature releases and long-term support releases serve different schedules; check the vendor’s support information rather than assuming the highest number is always the right choice.
Oracle JDK and Eclipse Temurin are two JDK distributions. Read the selected vendor’s licence and installation guidance. This guide uses the official graphical installer; you do not need to download an untrusted bundle or copy files into Windows system directories.
Download and install
On the vendor’s official downloads page, choose a Windows installer for your machine’s architecture and your selected JDK release. Oracle offers a self-installing executable; Eclipse Temurin offers an MSI installer for supported Windows x64 systems. Run the installer and follow its prompts. With Temurin MSI, the PATH feature is available by default and setting JAVA_HOME is optional in Custom Setup.
When installation finishes, close and reopen PowerShell so it reads the updated PATH. If you use an IDE, it may also need to be restarted or pointed at the installed JDK. Do not assume an IDE’s bundled runtime is the JDK used by your terminal.
Verify in PowerShell
Run the two version commands below. java -version identifies the launcher; javac -version identifies the compiler. Both should report a version appropriate to your chosen JDK. Get-Command shows which executable Windows finds first. An installed runtime without javac is insufficient for this compile-and-run tutorial.
PowerShell — check the selected tools
java -version
javac -version
Get-Command java
Get-Command javacCompile and run a file
Create a folder, save the example as Main.java, open PowerShell in that folder and run the compile and launch commands. The output should be Hello, Codectionary!. The public class name must match the filename, including letter case. No IDE or external package is needed for this example.
The compiler creates Main.class. If you change the message, run javac again before java Main or you may see the old output.
Main.java
public class Main {
public static void main(String[] args) {
System.out.println("Hello, Codectionary!");
}
}PowerShell — compile and run
javac Main.java
java MainCommon Windows setup problems
If java or javac is not recognised, reopen PowerShell, inspect Get-Command and check whether the installer added the JDK bin directory to PATH. If java and javac report different releases, more than one Java installation may be on PATH; choose the intended JDK in the environment or IDE before retrying. If the source file seems missing, check the terminal’s current folder with Get-Location and confirm the filename is Main.java, not Main.java.txt.
A “Could not find or load main class Main” error usually means the class was not compiled successfully, you are in the wrong folder or the class name differs. Read the first compiler error before changing other settings.
Syntax
java -version
javac -versionExamples
A Windows JDK smoke test
Run from a folder containing Main.java after both version commands succeed.
public class Main {
public static void main(String[] args) {
System.out.println("Hello, Codectionary!");
}
}- Main.java contains a public class whose name matches the filename.
- javac Main.java compiles the file; java Main launches its main method.
- System.out.println prints the greeting in PowerShell. Recompile after an edit.
Best practices
- Use a maintained JDK release that fits your course or project; check the vendor’s release and support information.
- Check both java and javac in a newly opened terminal after installation.
- Never paste passwords, tokens or private data into a remote code runner.
Runtime & versions
Java Virtual Machine. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
Java Language Specification