LearnContact
Lesson 440 min read

Java Installation

Learn how to install and configure Java correctly. Understand JDK selection, Java versions, environment variables, PATH configuration, JAVA_HOME, command-line verification, IDE setup, and common installation problems.

Introduction

Before writing Java programs, you need a properly configured Java development environment. This means installing a Java Development Kit, verifying the installation, and ensuring that your operating system can find Java commands.

Java installation is more than clicking an installer. A developer should understand where the JDK is installed, what the bin directory contains, how the PATH environment variable works, what JAVA_HOME represents, and how development tools discover the correct Java installation.

A correctly configured Java environment allows you to compile and run programs from the command line, use development tools, configure IDEs, build projects, and work with frameworks later in your Java journey.

Java Setup Process
CHOOSE JAVA VERSION

        │
        ▼

CHOOSE JDK DISTRIBUTION

        │
        ▼

DOWNLOAD JDK

        │
        ▼

INSTALL JDK

        │
        ▼

CONFIGURE PATH

        │
        ▼

CONFIGURE JAVA_HOME

        │
        ▼

VERIFY java

        │
        ▼

VERIFY javac

        │
        ▼

COMPILE TEST PROGRAM

        │
        ▼

RUN TEST PROGRAM

        │
        ▼

JAVA ENVIRONMENT READY
What You Will Learn
  • What software is required for Java development.
  • Whether you need a JDK or JRE.
  • How to choose a Java version.
  • How Java version numbers work.
  • What LTS versions are.
  • How to choose a JDK distribution.
  • How to identify your system architecture.
  • How to check whether Java is already installed.
  • How to install Java on Windows.
  • How to understand the JDK installation directory.
  • What the JDK bin directory contains.
  • What environment variables are.
  • What the PATH variable does.
  • How to configure PATH on Windows.
  • What JAVA_HOME means.
  • How to configure JAVA_HOME.
  • How to verify Java installation.
  • How Java installation works on macOS.
  • How Java installation works on Linux.
  • The difference between java and javac.
  • How to check JAVA_HOME.
  • How to create a test Java program.
  • How to compile a Java source file.
  • How to run a compiled Java program.
  • What files are created during compilation.
  • The difference between an IDE and a JDK.
  • How to configure a JDK inside an IDE.
  • How multiple JDK installations work.
  • How to find which Java executable is running.
  • How PATH order affects Java selection.
  • How project Java versions differ from system Java versions.
  • How to solve common installation errors.

What You Need for Java Development

The minimum requirement for learning Java development is a Java Development Kit and a text editor or Integrated Development Environment.

JDK

Provides the compiler, runtime, standard libraries, and development tools required for Java programming.

Code Editor

A simple text editor can be used to create Java source files.

Terminal

Used to compile and run Java programs using commands.

IDE

Optional but useful for professional development, debugging, project management, and code assistance.

Minimum Setup
REQUIRED

JDK
+
Text Editor
+
Terminal


OPTIONAL

IDE
Recommended Learning Approach
  • First learn how to compile and run Java from the command line.
  • Then use an IDE for larger programs.
  • Understanding command-line execution makes IDE behavior easier to understand.

Do You Need JDK or JRE?

To develop Java applications, install a JDK. The JDK contains the tools required to compile and run Java programs.

What Should You Install?
WANT TO WRITE JAVA CODE?

        │
        ▼

YES

        │
        ▼

INSTALL JDK


WHY?

JDK CONTAINS

├── javac Compiler
├── java Launcher
├── Development Tools
├── Runtime Components
└── JVM Capabilities
For This Course
  • Install a JDK.
  • Do not search only for a traditional standalone JRE.
  • The compiler is required for the lessons in this course.
  • A runtime-only environment is not enough for normal Java development.

Choosing a Java Version

Java has many versions. Before installing a JDK, you should know which version your course, project, organization, or framework requires.

Version Selection
CHOOSING JAVA VERSION

        │
        ├── Learning Requirement
        │
        ├── Project Requirement
        │
        ├── Framework Compatibility
        │
        ├── Library Compatibility
        │
        ├── Build Tool Configuration
        │
        └── Organization Standard
Important Rule
  • Do not automatically install the newest version for every project.
  • Use the version required by the project.
  • For general learning, an appropriate supported version is usually preferred.
  • For professional work, compatibility requirements decide the version.

Understanding Java Version Numbers

Modern Java releases are commonly identified by a feature version number such as Java 17, Java 21, or Java 25.

Version Examples
JAVA 8

JAVA 11

JAVA 17

JAVA 21

JAVA 25

The complete version displayed by the java command may contain additional update, build, and distribution information.

Example Version Structure
FEATURE VERSION

21

        │
        ▼

UPDATE INFORMATION

21.0.x

        │
        ▼

BUILD INFORMATION

21.0.x+build
Version Output Can Differ
  • Different JDK distributions may display version information differently.
  • The important value for most beginners is the major Java feature version.
  • Project compatibility may depend on more than the feature version.

What are LTS Versions?

LTS stands for Long-Term Support. LTS releases are commonly selected by organizations that want longer maintenance and support lifecycles from their chosen JDK provider.

Longer Support

LTS releases are commonly supported for longer periods by JDK providers.

Enterprise Adoption

Organizations often prefer LTS versions for long-lived production applications.

Ecosystem Stability

Libraries and frameworks commonly provide strong support for widely adopted LTS releases.

Upgrade Planning

Teams can plan migrations between major long-term support releases.

LTS Does Not Mean Permanent
  • Support duration depends on the JDK provider.
  • Different vendors may offer different support policies.
  • Applications still require updates and maintenance.
  • Always check project requirements before selecting a version.

Choosing a JDK Distribution

Java developers can choose from multiple JDK distributions. A distribution is a packaged JDK provided by a vendor or project.

Different distributions may use the same Java platform foundations while differing in packaging, support, update policies, licensing, included components, and runtime implementation choices.

JDK Distribution Concept
JAVA PLATFORM

        │
        ▼

JDK IMPLEMENTATIONS

        │
        ▼

DIFFERENT DISTRIBUTIONS

├── Distribution A
├── Distribution B
├── Distribution C
└── Distribution D

        │
        ▼

AVAILABLE FOR

Windows
Linux
macOS
Different CPU Architectures
For Beginners
  • Choose a reputable JDK distribution.
  • Choose the correct Java version.
  • Choose the correct operating system.
  • Choose the correct CPU architecture.
  • Use the same major Java version throughout the course.

Check Your System Architecture

JDK downloads are often available for different processor architectures. You must select a build compatible with your computer.

x64

Common on modern Intel and AMD desktop and laptop computers.

ARM64

Used by many ARM-based computers and modern Apple Silicon systems.

Download Selection
YOUR COMPUTER

        │
        ▼

OPERATING SYSTEM

Windows / Linux / macOS

        │
        ▼

PROCESSOR ARCHITECTURE

x64 / ARM64

        │
        ▼

CORRECT JDK PACKAGE
Common Download Mistake
  • Do not select a package only by Java version.
  • The operating system must match.
  • The processor architecture must match.
  • The package type should match your installation preference.

Check Whether Java is Already Installed

Before installing another JDK, check whether Java is already available on your computer.

Check Java Runtime
java -version
Check Java Compiler
javac -version
Possible Results
RESULT 1

java command works
javac command works

        │
        ▼

JDK LIKELY AVAILABLE


RESULT 2

java command works
javac command fails

        │
        ▼

RUNTIME MAY EXIST
BUT COMPILER IS NOT AVAILABLE


RESULT 3

Both commands fail

        │
        ▼

JAVA MAY NOT BE INSTALLED
OR PATH IS NOT CONFIGURED
Do Not Assume
  • A working java command does not always prove that the expected JDK is configured.
  • A working javac command confirms that a Java compiler is available through the current command environment.
  • The java and javac commands can theoretically come from different installations if PATH is incorrectly configured.

Install Java on Windows

On Windows, Java installation normally involves downloading a JDK package, installing or extracting it, configuring environment variables, and verifying the commands.

Windows Installation Process
DOWNLOAD JDK

        │
        ▼

RUN INSTALLER
OR
EXTRACT ARCHIVE

        │
        ▼

LOCATE JDK DIRECTORY

        │
        ▼

CONFIGURE JAVA_HOME

        │
        ▼

ADD bin TO PATH

        │
        ▼

OPEN NEW TERMINAL

        │
        ▼

VERIFY INSTALLATION

Download the JDK

Choose a JDK package that matches your required Java version, Windows version, processor architecture, and preferred package format.

Example Selection
JAVA VERSION

        │
        ▼

Required Version

        │
        ▼

OPERATING SYSTEM

Windows

        │
        ▼

ARCHITECTURE

x64

        │
        ▼

PACKAGE TYPE

Installer
or
Archive

Installer

Provides a guided installation process and usually creates a standard installation directory.

Archive

Can be extracted manually and may be useful when administrative installation is unavailable.

Run the Installer

If you downloaded an installer package, launch it and follow the installation steps. Pay attention to the destination directory because you may need that path when configuring JAVA_HOME.

Installer Flow
START INSTALLER

        │
        ▼

ACCEPT OR REVIEW OPTIONS

        │
        ▼

SELECT INSTALLATION DIRECTORY

        │
        ▼

INSTALL FILES

        │
        ▼

FINISH INSTALLATION
Remember the Installation Location
  • The JDK directory contains the Java development environment.
  • JAVA_HOME normally points to the JDK root directory.
  • PATH normally includes the JDK bin directory.

Understanding the JDK Installation Directory

The JDK installation directory contains executables, libraries, configuration files, modules, legal information, and other runtime resources.

Simplified JDK Directory
jdk-version

├── bin
│   ├── java
│   ├── javac
│   ├── jar
│   ├── javadoc
│   └── Other Tools
│
├── conf
│
├── include
│
├── jmods
│
├── legal
│
├── lib
│
└── Other Files
Directory Contents Can Vary
  • Exact files and folders can differ by Java version.
  • Different JDK distributions may package components differently.
  • The bin directory is especially important for command-line usage.

The bin Directory

The bin directory contains executable Java development and runtime commands.

JDK bin Directory
JDK ROOT

    │
    ▼

bin

├── java
├── javac
├── jar
├── javadoc
├── javap
├── jshell
└── Other Commands

When the JDK bin directory is available through PATH, you can run Java commands from different directories without typing the complete executable path.

Without PATH
FULL PATH REQUIRED

C:\Path\To\JDK\bin\java.exe -version
With PATH
SIMPLE COMMAND

java -version

Environment Variables

Environment variables are named values that programs and operating systems can use to locate tools, directories, configuration information, and other resources.

PATH

Tells the operating system where to search for executable commands.

JAVA_HOME

Conventionally identifies the root directory of a Java installation.

Java Environment Variables
JAVA_HOME

        │
        ▼

JDK ROOT DIRECTORY


PATH

        │
        ▼

INCLUDES

JDK bin DIRECTORY

What is PATH?

PATH is an environment variable containing a list of directories. When you enter a command, the operating system searches these directories to find a matching executable.

How PATH Works
USER TYPES

java -version

        │
        ▼

OPERATING SYSTEM SEARCHES PATH

Directory 1
    │
    ▼
Not Found

Directory 2
    │
    ▼
Not Found

JDK bin Directory
    │
    ▼
java Found

        │
        ▼

COMMAND EXECUTES
Why PATH Matters
  • Without PATH configuration, Java may still be installed.
  • However, the terminal may not know where to find java or javac.
  • Adding the JDK bin directory to PATH makes the commands globally accessible.

Configure PATH on Windows

On Windows, the JDK bin directory can be added to the PATH environment variable.

Recommended Concept
JAVA_HOME

C:\Path\To\JDK

        │
        ▼

PATH ENTRY

%JAVA_HOME%\bin
  • Open the Windows environment variable settings.
  • Locate the appropriate PATH variable.
  • Add the JDK bin directory.
  • Avoid deleting existing PATH entries.
  • Save the changes.
  • Close old terminals.
  • Open a new terminal.
  • Run java -version.
  • Run javac -version.
Be Careful When Editing PATH
  • Do not replace the entire PATH value with the Java path.
  • Add a new entry instead.
  • Removing existing PATH entries can break other installed software.
  • PATH order matters when multiple Java installations exist.

What is JAVA_HOME?

JAVA_HOME is a commonly used environment variable that points to the root directory of a Java installation.

JAVA_HOME
CORRECT CONCEPT

JAVA_HOME
=
C:\Path\To\JDK


NOT

C:\Path\To\JDK\bin


NOT

C:\Path\To\JDK\bin\java.exe
Simple Rule
  • JAVA_HOME points to the JDK root.
  • PATH points to or includes the JDK bin directory.
  • Many development tools use JAVA_HOME to locate Java.

Configure JAVA_HOME

Create an environment variable named JAVA_HOME and assign the JDK root directory as its value.

Configuration
VARIABLE NAME

JAVA_HOME


VARIABLE VALUE

C:\Path\To\JDK
Use JAVA_HOME in PATH
PATH

Existing Entry 1
Existing Entry 2
%JAVA_HOME%\bin
Existing Entry 3
Common JAVA_HOME Mistake
  • Do not point JAVA_HOME to the bin directory.
  • Do not point JAVA_HOME directly to java.exe.
  • Do not include unnecessary quotation marks in the stored value unless a specific tool requires them.
  • Make sure the directory actually exists.

Verify Java Installation on Windows

After configuring Java, close existing terminals and open a new Command Prompt, PowerShell, or terminal window.

Check Runtime
java -version
Check Compiler
javac -version
Successful Verification
java -version

        │
        ▼

VERSION INFORMATION DISPLAYED


javac -version

        │
        ▼

COMPILER VERSION DISPLAYED


RESULT

JDK COMMANDS ARE ACCESSIBLE
Basic Verification Complete
  • java command works.
  • javac command works.
  • Both show the expected major Java version.
  • The system can find the JDK tools.

Install Java on macOS

On macOS, Java can be installed using a compatible JDK package or a package-management approach. The selected JDK must match the machine architecture.

macOS Architecture
MAC COMPUTER

        │
        ├── Intel Processor
        │       │
        │       ▼
        │      x64 JDK
        │
        └── Apple Silicon
                │
                ▼
              ARM64 JDK

After installation, the system can use Java tools from the terminal. JAVA_HOME can also be configured for development tools that require it.

Discover Java Home on macOS
/usr/libexec/java_home
Set JAVA_HOME for Current Shell
export JAVA_HOME=$(/usr/libexec/java_home)
Shell Configuration
  • Temporary export commands affect the current shell session.
  • Persistent configuration is usually added to the appropriate shell configuration file.
  • The correct file depends on the shell being used.

Verify Java on macOS

Check Java
java -version
Check Compiler
javac -version
Check JAVA_HOME
echo $JAVA_HOME
Successful macOS Setup
  • java reports the expected version.
  • javac reports the expected version.
  • JAVA_HOME points to the intended JDK when required.

Install Java on Linux

On Linux, a JDK can be installed through the distribution package manager or by installing a downloaded JDK package manually.

Linux Installation Options
LINUX

        │
        ├── Package Manager
        │
        │       │
        │       ▼
        │   Distribution Package
        │
        └── Manual Installation
                │
                ▼
          Downloaded JDK Package

Package names and installation commands vary between Linux distributions and Java versions.

Linux Commands Differ
  • Debian-based distributions use different package tools from Red Hat-based distributions.
  • Package names depend on the repository.
  • The default Java version may differ between Linux distributions.
  • Verify the installed version after installation.

Verify Java on Linux

Check Java
java -version
Check Compiler
javac -version
Find Java Executable
which java
Check JAVA_HOME
echo $JAVA_HOME

The java Command

The java command launches Java applications and starts the Java runtime environment required for execution.

Version
java -version
Run a Class
java Hello
java Command Purpose
java

USED TO

├── Start Java Runtime
├── Load Application Classes
├── Start JVM Execution
└── Run Java Applications

The javac Command

The javac command is the Java compiler. It translates Java source code into Java bytecode.

Compiler Version
javac -version
Compile Source File
javac Hello.java
javac Command Purpose
javac

INPUT

.java Source File

        │
        ▼

COMPILATION

        │
        ▼

OUTPUT

.class Bytecode File

java vs javac

java and javac
javac

ROLE:
Compiler

INPUT:
Hello.java

OUTPUT:
Hello.class


java

ROLE:
Application Launcher

INPUT:
Class Name

ACTION:
Starts Java Execution

javac

Compiles Java source files into bytecode.

java

Launches and executes Java applications.

Common Beginner Mistake
  • Compile with: javac Hello.java
  • Run with: java Hello
  • Do not run with: java Hello.java when learning the traditional compile-and-run process.
  • Do not run with: java Hello.class.

Check JAVA_HOME

After configuration, verify that JAVA_HOME points to the intended JDK directory.

Windows Command Prompt
echo %JAVA_HOME%
Windows PowerShell
$env:JAVA_HOME
macOS and Linux
echo $JAVA_HOME
Expected Concept
JAVA_HOME

        │
        ▼

JDK ROOT

        │
        ├── bin
        ├── conf
        ├── lib
        └── Other JDK Directories

Your First Installation Test Program

The strongest installation test is not only checking version commands. Create, compile, and run a real Java program.

Complete Test
CREATE

Hello.java

        │
        ▼

COMPILE

javac Hello.java

        │
        ▼

GENERATE

Hello.class

        │
        ▼

RUN

java Hello

        │
        ▼

VERIFY OUTPUT

Create the Source File

Create a new file named Hello.java.

Hello.java
public class Hello {

    public static void main(String[] args) {

        System.out.println(
            "Java is installed correctly!"
        );

    }

}
Check the Filename
  • The filename must be Hello.java.
  • The public class name is Hello.
  • The filename and public class name must match exactly.
  • Make sure the file is not accidentally saved as Hello.java.txt.

Compile the Program

Open a terminal in the directory containing Hello.java and compile the source file.

Compile
javac Hello.java
Compilation Result
BEFORE

Hello.java


AFTER SUCCESSFUL COMPILATION

Hello.java
Hello.class
No Output Can Mean Success
  • javac may display nothing when compilation succeeds.
  • Check whether Hello.class was created.
  • Compilation errors are displayed when the source code is invalid.

Run the Program

Run the compiled class using the java command.

Run
java Hello
Output
Java is installed correctly!
Installation Confirmed
  • The Java compiler works.
  • The Java launcher works.
  • The JVM can start.
  • The source file can be compiled.
  • The generated bytecode can be executed.

Understanding the Generated Files

Source and Class Files
Hello.java

TYPE:
Source File

CREATED BY:
Developer

CONTAINS:
Java Source Code


Hello.class

TYPE:
Compiled Class File

CREATED BY:
javac

CONTAINS:
Java Bytecode
Complete Flow
Hello.java

    │
    ▼

javac Hello.java

    │
    ▼

Hello.class

    │
    ▼

java Hello

    │
    ▼

JVM EXECUTION

    │
    ▼

PROGRAM OUTPUT

Install an IDE

An Integrated Development Environment provides tools for writing, organizing, running, testing, and debugging applications.

Code Editor

Provides syntax highlighting, formatting, and code assistance.

Run Tools

Allows applications to be launched without manually typing every command.

Debugger

Allows developers to inspect program execution step by step.

Project Management

Organizes source code, libraries, resources, and configuration.

Code Intelligence

Provides completion, navigation, inspections, and refactoring support.

Testing Support

Helps create, run, and inspect automated tests.

IDE is Optional for Basic Java
  • Java can be written using a simple text editor.
  • Java can be compiled using javac.
  • Java can be run using the java command.
  • An IDE improves productivity but does not replace understanding Java fundamentals.

IDE vs JDK

IDE and JDK
IDE

USED FOR

Writing Code
Managing Projects
Debugging
Code Assistance


JDK

USED FOR

Compiling Java
Running Java
Providing Java Tools
Providing Runtime Capabilities
They Are Not the Same
  • An IDE is a development application.
  • A JDK is the Java development toolkit.
  • An IDE usually needs access to a JDK for Java development.
  • Installing an IDE does not always mean your system Java configuration is correct.

Configure JDK in an IDE

An IDE may detect installed JDKs automatically, allow you to select an existing JDK, or provide a mechanism for downloading one.

IDE JDK Configuration
IDE

        │
        ▼

PROJECT SETTINGS

        │
        ▼

SELECT JDK

        │
        ├── Existing JDK
        │
        └── Downloaded JDK

        │
        ▼

PROJECT USES SELECTED JAVA VERSION
Important
  • The IDE JDK can differ from the java command used in your terminal.
  • The project SDK can differ from JAVA_HOME.
  • The build tool can also use a separately configured Java installation.
  • Always verify which JDK each tool is actually using.

Multiple JDK Versions

A computer can have multiple JDK versions installed at the same time.

Multiple Java Installations
COMPUTER

├── JDK 17
│
├── JDK 21
│
└── JDK 25


DIFFERENT PROJECTS

Project A ─────► JDK 17

Project B ─────► JDK 21

Project C ─────► JDK 25
Why Multiple JDKs Are Useful
  • Older projects may require older Java versions.
  • New projects may use newer Java versions.
  • Framework compatibility can differ.
  • Developers may test applications across versions.

Which Java is Running?

When multiple Java installations exist, you should identify which executable your terminal is actually using.

Windows
where java
macOS and Linux
which java
Command Resolution
USER TYPES

java

        │
        ▼

SYSTEM SEARCHES PATH

        │
        ▼

FIRST MATCHING java EXECUTABLE

        │
        ▼

THAT JAVA VERSION RUNS
Version Command Alone May Not Be Enough
  • java -version tells you the active runtime version.
  • where java or which java helps identify the executable location.
  • Check both when troubleshooting multiple installations.

Switch Between Java Versions

Switching Java versions generally means changing which JDK your terminal, IDE, build tool, or project uses.

Possible Java Version Controls
SYSTEM LEVEL

PATH
JAVA_HOME


IDE LEVEL

Project SDK
Language Level


BUILD TOOL LEVEL

Tool Configuration
Toolchain Configuration


PROJECT LEVEL

Source Version
Target Version
Release Version
Java Version Has Multiple Layers
  • Terminal Java version.
  • JAVA_HOME version.
  • IDE project JDK.
  • Build tool JDK.
  • Compiler target version.
  • Application runtime version.

PATH Order

When multiple directories contain a command with the same name, PATH order determines which executable is found first.

PATH Order Example
PATH ORDER

1. C:\JDK17\bin

2. C:\JDK21\bin

3. Other Directories


USER TYPES

java


FIRST MATCH

C:\JDK17\bin\java


RESULT

JDK 17 RUNS
Common Multiple-JDK Problem
  • JAVA_HOME points to one JDK.
  • PATH points to another JDK.
  • java and javac may not match.
  • The IDE may use a third JDK.
  • Always inspect the complete configuration.

System Java Version vs Project Java Version

The Java version installed on your computer is not always the same as the version used by a particular project.

Different Version Layers
COMPUTER

Default Terminal Java
JDK 21


IDE PROJECT

Configured JDK
JDK 17


BUILD TOOL

Configured Toolchain
JDK 17


APPLICATION

Compiled Target
Java 17
Why This Matters
  • A project can fail even when java -version looks correct.
  • The IDE may compile with a different JDK.
  • The build tool may launch with another Java version.
  • Always check the specific tool reporting the error.

Common Installation Errors

Most Java installation problems are caused by incorrect paths, multiple installations, mismatched versions, terminal sessions using old environment values, or confusion between runtime and compiler commands.

Troubleshooting Flow
JAVA COMMAND FAILS

        │
        ▼

IS JDK INSTALLED?

        │
        ▼

IS bin IN PATH?

        │
        ▼

IS JAVA_HOME CORRECT?

        │
        ▼

WHICH EXECUTABLE IS USED?

        │
        ▼

DO java AND javac MATCH?

        │
        ▼

RESTART TERMINAL

        │
        ▼

VERIFY AGAIN

Error: java is not recognized

Typical Error
'java' is not recognized as an internal
or external command

This usually means the operating system cannot find the Java executable through the current PATH.

Possible Causes
  • The JDK is not installed.
  • The JDK bin directory is not in PATH.
  • The PATH entry contains a typing mistake.
  • The terminal was opened before PATH was changed.
  • Another broken Java path appears earlier in PATH.
Solution Concept
VERIFY JDK EXISTS

        │
        ▼

VERIFY bin DIRECTORY EXISTS

        │
        ▼

ADD bin TO PATH

        │
        ▼

OPEN NEW TERMINAL

        │
        ▼

RUN

java -version

Error: javac is not recognized

If java works but javac does not, the system may be using an environment that provides runtime execution but does not expose the expected JDK compiler.

Possible Causes
  • Only a runtime environment is accessible.
  • PATH points to the wrong Java installation.
  • The JDK bin directory is missing from PATH.
  • Multiple Java installations are conflicting.
  • The JDK installation is incomplete.
Check Both
java -version

javac -version

where java

where javac

Wrong Java Version

Sometimes Java is installed correctly, but the terminal displays a different version from the one you expect.

Example Problem
EXPECTED

Java 21


COMMAND

java -version


ACTUAL

Java 17
Check These Areas
  • PATH order.
  • JAVA_HOME value.
  • Location returned by where java or which java.
  • Old Java installation entries.
  • IDE JDK settings.
  • Build tool settings.

JAVA_HOME is Incorrect

Incorrect Values
WRONG

JAVA_HOME =
C:\Path\To\JDK\bin


WRONG

JAVA_HOME =
C:\Path\To\JDK\bin\java.exe


CORRECT CONCEPT

JAVA_HOME =
C:\Path\To\JDK
Verify JAVA_HOME
  • The directory should exist.
  • The directory should be the JDK root.
  • The bin directory should exist inside it.
  • The javac executable should be available inside the bin directory.

Terminal Shows the Old Java Version

A terminal process normally receives environment variables when it starts. If you change PATH or JAVA_HOME while the terminal is already open, the existing terminal may continue using old values.

Environment Refresh
CHANGE ENVIRONMENT VARIABLES

        │
        ▼

OLD TERMINAL

May Still Use Old Values

        │
        ▼

CLOSE TERMINAL

        │
        ▼

OPEN NEW TERMINAL

        │
        ▼

NEW VALUES LOADED
First Troubleshooting Step
  • Close the terminal.
  • Open a new terminal.
  • Run java -version again.
  • Run javac -version again.

Spaces in Installation Paths

Java installations can exist in directories containing spaces. Problems usually occur when scripts or commands handle such paths incorrectly.

Path Example
C:\Program Files\Java\jdk-version
Be Careful in Scripts
  • Paths containing spaces may require correct quoting in commands or scripts.
  • Environment variable editors usually store the directory value directly.
  • Do not add random quotation marks unless the context requires them.
  • Always inspect the actual path used by the failing tool.

Java Installation Checklist

Complete Checklist
JAVA INSTALLATION CHECKLIST

[ ] Correct Java version selected

[ ] Correct JDK distribution selected

[ ] Correct operating system selected

[ ] Correct CPU architecture selected

[ ] JDK installed or extracted

[ ] JDK directory identified

[ ] JAVA_HOME configured if required

[ ] JDK bin added to PATH

[ ] New terminal opened

[ ] java -version works

[ ] javac -version works

[ ] java and javac versions match expectations

[ ] Correct executable location verified

[ ] Hello.java created

[ ] Hello.java compiled

[ ] Hello.class generated

[ ] java Hello runs successfully

[ ] IDE configured with correct JDK
Your Setup is Ready When
  • You can run java -version.
  • You can run javac -version.
  • You can compile a .java file.
  • You can run the generated class.
  • Your IDE recognizes the intended JDK.

Common Misconceptions

Avoid These Misconceptions
  • Installing an IDE is not the same as understanding Java installation.
  • An IDE and a JDK are different tools.
  • Java development requires compiler access.
  • java and javac are different commands.
  • java runs applications.
  • javac compiles source code.
  • JAVA_HOME should normally point to the JDK root.
  • JAVA_HOME should not normally point to the bin directory.
  • PATH and JAVA_HOME are not the same variable.
  • Adding JAVA_HOME alone does not automatically make java available in every terminal configuration.
  • The JDK bin directory must be discoverable for command-line tools.
  • A working java command does not always mean javac is available.
  • Multiple JDK versions can exist on one computer.
  • The newest installed JDK is not automatically the one being used.
  • PATH order can decide which Java executable runs.
  • The terminal JDK can differ from the IDE JDK.
  • The IDE JDK can differ from the build tool JDK.
  • A project can target a Java version different from the default terminal version.
  • Changing environment variables may not update already-open terminals.
  • java Hello and java Hello.class are not the same command.
  • The class name is used when running a compiled class.
  • The source filename and public class name must match.
  • A file named Hello.java.txt is not a proper Java source filename.
  • Successful javac execution may produce no terminal output.
  • The generated .class file contains bytecode.
  • A JDK distribution and a Java version are not the same concept.
  • LTS support policies can differ between JDK providers.
  • System architecture matters when selecting a JDK package.
  • Platform-specific installation instructions can differ.

Common Interview Questions

What do you need to develop Java applications?

You need a JDK because it provides the compiler, runtime capabilities, libraries, and development tools.

What is the difference between java and javac?

javac compiles Java source code into bytecode, while java launches and executes Java applications.

What is JAVA_HOME?

JAVA_HOME is a commonly used environment variable that points to the root directory of a Java installation.

What is PATH?

PATH is an environment variable containing directories that the operating system searches for executable commands.

Should JAVA_HOME point to the bin directory?

Normally no. JAVA_HOME should point to the JDK root directory.

Why is the JDK bin directory added to PATH?

It allows commands such as java and javac to be executed without typing their complete file paths.

Can multiple JDK versions be installed?

Yes. A computer can contain multiple JDK versions for different projects.

How do you check the Java version?

Use the java -version command.

How do you check the Java compiler version?

Use the javac -version command.

How do you find which Java executable is being used?

Use where java on Windows or which java on macOS and Linux.

Why can JAVA_HOME and java -version show different Java installations?

The java command is resolved through PATH, while JAVA_HOME is a separate environment variable. Incorrect configuration can make them point to different JDKs.

What file does javac generate?

javac normally generates one or more .class files containing Java bytecode.

Why must the public class name match the filename?

A public top-level class must be declared in a source file with the corresponding class name.

Why does an old terminal sometimes show an old Java version?

The terminal may have loaded environment variables before the configuration was changed.

Can an IDE use a different JDK from the terminal?

Yes. IDE project settings can select a JDK independently from the terminal PATH configuration.

Frequently Asked Questions

Which Java version should I install?

Install the version required by your course or project. For general learning, use an appropriate supported version and keep the same major version throughout the course.

Do I need both JDK and JRE?

For Java development, install a JDK. Modern JDKs provide the capabilities required to compile and run Java applications.

Do I need an IDE to learn Java?

No. You can write Java using a text editor and compile and run programs from the command line.

Should I learn command-line Java before using an IDE?

It is useful because it helps you understand source files, compilation, bytecode, class files, and execution.

Can I install Java without administrator privileges?

Depending on the JDK distribution and operating system, an archive-based JDK can often be extracted into a user-accessible directory and configured for the current user.

Why does java work but javac fail?

The current environment may expose runtime execution but not the expected JDK compiler, or PATH may point to the wrong installation.

Why does javac work in one terminal but not another?

Different terminals can have different environment configurations or may have been opened before environment variables were changed.

Can I install Java on another drive?

Yes. The important requirement is that your configuration points to the correct installation directory.

Can JAVA_HOME contain spaces?

Yes. The path can contain spaces, but scripts and commands must handle such paths correctly.

Why does java -version show a different version from my IDE?

The terminal and IDE can be configured to use different JDK installations.

Why does my build tool use another Java version?

Build tools can use JAVA_HOME, IDE settings, toolchains, wrappers, or their own configuration.

What happens if multiple Java paths are in PATH?

The first matching executable found according to PATH order is normally used.

Should I delete old JDK versions?

Not necessarily. Keep versions required by existing projects, but remove unused versions carefully if they cause confusion or are no longer supported.

What proves that Java is installed correctly?

A strong verification is successfully running java -version, javac -version, compiling a source file, and executing the generated class.

Why was Hello.class created?

The javac compiler translated Hello.java into Java bytecode stored in Hello.class.

Why do I run java Hello instead of java Hello.class?

The java launcher expects the class name in this traditional execution process, not the class filename.

Can the source file and class file exist together?

Yes. The source file contains Java code, while the class file contains compiled bytecode.

Do I need JAVA_HOME for every simple Java command?

The java and javac commands can work through PATH, but many development tools and build systems use JAVA_HOME.

Can different projects use different Java versions?

Yes. Professional development environments commonly use different JDK versions for different projects.

Key Takeaways

  • Java development requires a JDK.
  • A JDK provides development tools and runtime capabilities.
  • A text editor and terminal are enough for basic Java development.
  • An IDE is optional but useful.
  • The Java version should match project requirements.
  • The newest Java version is not always the correct version for a project.
  • LTS means Long-Term Support.
  • Support policies can differ between JDK providers.
  • Multiple JDK distributions are available.
  • The operating system must match the selected JDK package.
  • The processor architecture must match the selected JDK package.
  • x64 and ARM64 are common architectures.
  • Use java -version to check the active Java runtime.
  • Use javac -version to check the Java compiler.
  • The JDK installation contains a bin directory.
  • The bin directory contains Java executable tools.
  • java launches Java applications.
  • javac compiles Java source code.
  • PATH helps the operating system find executable commands.
  • The JDK bin directory should be available through PATH for convenient command-line usage.
  • JAVA_HOME normally points to the JDK root directory.
  • JAVA_HOME should not normally point to the bin directory.
  • PATH and JAVA_HOME serve different purposes.
  • Environment variable changes may require a new terminal session.
  • A computer can contain multiple JDK installations.
  • PATH order affects which Java executable is selected.
  • where java can locate Java executables on Windows.
  • which java can locate the Java executable on macOS and Linux.
  • The terminal Java version can differ from the IDE Java version.
  • The build tool Java version can differ from the terminal version.
  • A project can use a different JDK from the system default.
  • Hello.java is a Java source file.
  • javac Hello.java compiles the source file.
  • Successful compilation creates Hello.class.
  • Hello.class contains Java bytecode.
  • java Hello runs the compiled class.
  • The public class name should match the source filename.
  • Hello.java.txt is not the same as Hello.java.
  • A successful compilation may display no terminal output.
  • The best installation test is to compile and run a real Java program.
  • An IDE and JDK are not the same thing.
  • An IDE requires access to a suitable Java development environment.
  • Common installation problems involve PATH, JAVA_HOME, multiple JDKs, and version mismatches.
  • java and javac should normally report compatible expected versions.
  • Installation is complete when you can compile and execute a Java program successfully.

Summary

Installing Java correctly is the first practical step toward becoming a Java developer. A complete development setup requires a Java Development Kit, access to command-line tools, and correct environment configuration.

The JDK provides the tools required to create Java applications. The javac command compiles Java source code into bytecode, while the java command launches and executes Java applications.

Before installing a JDK, you should choose the correct Java version, JDK distribution, operating system package, and processor architecture. Project requirements should guide version selection.

The PATH environment variable allows the operating system to locate executable commands such as java and javac. The JDK bin directory must be accessible through PATH for convenient command-line usage.

JAVA_HOME is a commonly used environment variable that points to the JDK root directory. Many IDEs, build tools, servers, and development utilities use JAVA_HOME to locate Java.

A computer can contain multiple JDK installations. The version used by the terminal depends on command resolution and PATH order, while IDEs and build tools may use independently configured JDKs.

The strongest way to verify a Java installation is to create a source file, compile it with javac, confirm that a .class file is generated, and run the compiled class using the java command.

Understanding Java installation prepares you for every future lesson because you now know how the development tools are discovered, how source code is compiled, how bytecode is generated, and how Java applications are launched.

Lesson 4 Completed
  • You know what is required for Java development.
  • You know why a JDK is required.
  • You understand how to choose a Java version.
  • You understand Java version numbers.
  • You understand LTS releases.
  • You understand JDK distributions.
  • You know why system architecture matters.
  • You know how to check an existing Java installation.
  • You understand the Windows installation process.
  • You understand the JDK installation directory.
  • You understand the JDK bin directory.
  • You understand environment variables.
  • You know what PATH does.
  • You know how the JDK bin directory is added to PATH.
  • You know what JAVA_HOME means.
  • You know how JAVA_HOME should be configured.
  • You know how to verify Java on Windows.
  • You understand Java installation concepts on macOS.
  • You understand Java installation concepts on Linux.
  • You know what the java command does.
  • You know what the javac command does.
  • You understand the difference between java and javac.
  • You know how to check JAVA_HOME.
  • You know how to create a test Java source file.
  • You know how to compile a Java program.
  • You know how to run a compiled Java program.
  • You understand .java and .class files.
  • You understand the role of an IDE.
  • You understand the difference between an IDE and JDK.
  • You understand how IDE JDK configuration works.
  • You know that multiple JDK versions can coexist.
  • You know how to identify the active Java executable.
  • You understand how Java versions can be switched.
  • You understand PATH order.
  • You understand system and project Java versions.
  • You know how to troubleshoot common Java installation errors.
  • Your Java development environment is ready.
  • You are ready to write your first complete Java program.
Next Lesson →

First Java Program