To develop Java applications, install a Java Development Kit and verify both its compiler and launcher. An editor can make writing code comfortable, but it does not replace that toolchain. This lesson targets Java 17 or a compatible newer JDK and explains a setup you can check from a terminal. Installation screens and download versions vary by vendor and operating system; the durable checks are the selected distribution, executable locations, and a successful compile-and-run test.
Choose a supported JDK distribution
Select a reputable OpenJDK distribution or Oracle JDK appropriate to your operating system and processor architecture. Match the project's required feature release instead of assuming the newest download is automatically suitable. Check the vendor's support and licensing terms for your intended use. Download from its official source and follow its installation instructions. A Windows x64 installer, a macOS Apple-silicon package, and a Linux package are different artifacts despite serving the same toolchain role.
Install before editing environment variables
An installer may configure command access for you. A compressed archive usually requires extracting the JDK to a known directory and configuring tools yourself. The JDK home is the directory containing bin, not bin itself. Keep a clear record of that location. If several JDKs are installed, use a version manager or explicit tool settings rather than deleting installations blindly; another project may require one of those releases.
Understand PATH and JAVA_HOME
PATH is the search list used when a shell resolves java or javac. JAVA_HOME conventionally points build tools to a JDK home. Setting JAVA_HOME does not automatically guarantee that the shell's java command uses that installation: PATH can still select another executable first. Include the chosen JDK's bin directory in the relevant PATH configuration. After persistent environment changes, open a new terminal so it receives the updated environment.
Verify commands in the actual working terminal
Run both java -version and javac -version. Successful output confirms that the terminal can resolve the launcher and compiler, but compare their versions too. On Windows, where.exe shows matching command locations; a Unix-style shell can use command -v. A terminal embedded in an editor may have inherited older settings and require restarting the editor. Diagnose the environment where the command fails rather than relying on a different terminal's successful result.
Test a program before adding an IDE
A tiny source file confirms more than a download receipt. Compile it with javac and run its class with java. If the compiler cannot find the file, inspect the current directory. If the launcher cannot find the class, inspect its name and classpath. Starting with this simple test separates installation problems from build-tool configuration, project imports, and editor extensions. Only after it works should you configure the IDE's selected project JDK.
Keep development and project versions aligned
An IDE, Maven, Gradle, and the command shell can each use a different Java installation. Check their own settings when builds disagree. A project targeting Java 17 can compile on a newer JDK with an appropriate release setting, but it should be tested on the supported runtime. Avoid changing source syntax to work around a missing compiler; first establish the toolchain and then diagnose any genuine language or API incompatibility.
Practice tasks and checks
Write down the selected JDK home, the output of both version commands, and the locations of both executables. Compile SetupCheck with javac --release 17 SetupCheck.java and run it with java -cp . SetupCheck. Then close and reopen the terminal if you changed persistent environment settings and repeat the checks. This confirms the setup survives a new process rather than depending on a one-off session assignment. In your editor, select the same project JDK and run the same class. If the editor result differs, compare its configured runtime and working directory. Keep installation troubleshooting separate from changing the example's code: the message and main signature should remain unchanged throughout this verification.
Java Summary
- Verify both java and javac after installing a JDK.
- JAVA_HOME names the JDK home; PATH contains its bin directory.
- Confirm setup by compiling and running your own small program.
- Continue with compiling and launching when these examples are clear.
Java Examples
Each example shows the code, the output it produces and what each part does.
Check launcher and compiler
Use the following shell commands or configuration.
What to expect: Both commands report a Java feature version; exact vendor and patch text varies.
The first command reports the launcher and runtime installation selected by the shell. The second reports the compiler. If only the first succeeds, the machine may have execution support without a compiler on PATH. If both succeed but report different feature releases, inspect command locations before compiling a project. Version output often goes to standard error and that does not mean the command failed.
java -version
javac -versionConfigure a JDK for this PowerShell session
Use the following powershell commands or configuration.
What to expect: The two version commands use the JDK at your actual configured directory.
Replace the sample directory with the JDK directory that really exists on your machine. These assignments affect the current PowerShell process and child processes; they do not permanently edit the system environment. Placing bin first makes the chosen tools take precedence in that session. Do not reuse this path literally if your vendor installed the JDK elsewhere, and do not replace the entire existing PATH with only one directory.
$env:JAVA_HOME = "C:\Tools\jdk-17"
$env:Path = "$env:JAVA_HOME\bin;$env:Path"
java -version
javac -versionCompile a minimal installation check
Save this program as SetupCheck.java. Compile it with javac SetupCheck.java and run it with java SetupCheck.
Expected output:
The public class name determines the source filename SetupCheck.java. javac creates SetupCheck.class when compilation succeeds. The launcher receives the class name SetupCheck without a .class extension and invokes its main method. The exact message verifies that your own program ran, rather than merely that the java command displayed a version. Keep this file outside a complicated project while diagnosing initial setup.
public class SetupCheck {
public static void main(String[] args) {
System.out.println("Java toolchain ready");
}
}Java toolchain readyJava FAQ
Must I set JAVA_HOME to the bin directory?
No. It normally points to the JDK home containing bin. PATH includes that home's bin directory. Confusing the two locations can make build tools construct an invalid compiler path.
Why does my editor still use the old Java version?
Its process may have inherited an older environment, or its project configuration may explicitly select another JDK. Restart after environment changes and inspect the editor's Java runtime settings.
Can I have several JDK versions installed at once?
Yes. Each JDK lives in its own folder, and JAVA_HOME and PATH decide which one a terminal uses. Tools such as SDKMAN! on macOS and Linux switch between versions with one command, and IDEs let each project choose its own JDK.
Do I need administrator rights to install a JDK?
Not necessarily. Installers usually need them, but most distributions also offer a zip or tar archive that you can extract into your own user folder. Point JAVA_HOME at that folder and add its bin subfolder to PATH for your user account.
Is the JDK my IDE downloaded enough?
It's enough for running code inside the IDE. A terminal, Maven or Gradle won't see it unless JAVA_HOME and PATH point to it, which explains why programs can run in the IDE and fail on the command line. Check with java -version and javac -version in a terminal.
Java Exercises
Answer each one and check it instantly. If you get stuck, open the hint before the answer.
What should a development installation provide?
Where should JAVA_HOME point?
Java Quiz
2 questions to check what you learned.
What does changing $env:Path in PowerShell affect?
- The current session and its child processes
- Every computer on the network
- All stored files permanently
What is the launch command for SetupCheck.class in the current directory?
- java SetupCheck
- java SetupCheck.class
- javac SetupCheck.class