Lesson 1.5: Installing Java JDK
Introduction
Before writing Java programs, we need to install the Java Development Kit (JDK) on our computer.
The JDK contains all the tools required to develop Java applications, including the Java compiler (javac), Java Virtual Machine (JVM), Java Runtime Environment (JRE), and standard Java libraries.
In this lesson, you will learn how to download, install, and verify the Java Development Kit on Windows.
Learning Objectives
After completing this lesson, you will be able to:
-
Understand why the JDK is required.
-
Download the latest Java Development Kit.
-
Install the JDK on Windows.
-
Verify that Java has been installed correctly.
-
Understand the purpose of the PATH environment variable.
What is the Java Development Kit (JDK)?
The Java Development Kit (JDK) is the official software package required to create Java applications.
It includes:
-
Java Compiler (
javac) -
Java Runtime Environment (JRE)
-
Java Virtual Machine (JVM)
-
Standard Java Libraries
-
Development Tools
Without the JDK, you cannot compile Java source code.
System Requirements
Before installing Java, ensure that your computer meets these basic requirements:
-
Windows 10 or Windows 11
-
At least 4 GB RAM (8 GB recommended)
-
500 MB of free storage
-
Internet connection for downloading the installer
Step 1: Download the JDK
Download the latest Java Development Kit (JDK) from the official Oracle website or from OpenJDK.
Choose the installer according to your operating system:
-
Windows (x64)
-
Linux
-
macOS
For this course, we will use the Windows x64 Installer.
Tip: Always download Java from an official and trusted source.
Step 2: Run the Installer
After downloading:
-
Double-click the installer.
-
Click Next.
-
Choose the installation folder (default location is recommended).
-
Click Install.
-
Wait for the installation to complete.
-
Click Finish.
Java is now installed on your computer.
Step 3: Verify the Installation
Open Command Prompt.
Type the following command:
java -version
Example Output:
java version "21.0.x"
Java(TM) SE Runtime Environment
Java HotSpot(TM) 64-Bit Server VM
If you see similar output, Java is installed successfully.
Step 4: Verify the Java Compiler
Now check whether the Java compiler is available.
Type:
javac -version
Example Output:
javac 21.0.x
If this command works, your Java compiler has been installed successfully.
Understanding PATH Environment Variable
The PATH is an environment variable that tells Windows where to find executable programs such as java and javac.
If Java is added to the PATH, you can execute Java commands from any folder in the Command Prompt.
Without the PATH variable, Windows may display an error such as:
'java' is not recognized as an internal or external command.
How to Check Java Installation
Run these two commands:
java -version
javac -version
If both commands display version information, Java has been installed correctly.
Common Installation Problems
Problem 1: ‘java’ is not recognized
Possible Cause:
-
Java is not installed.
-
PATH variable is not configured correctly.
Solution:
-
Reinstall the JDK.
-
Ensure the installation completed successfully.
-
Restart the Command Prompt after installation.
Problem 2: ‘javac’ is not recognized
Possible Cause:
-
Compiler not found.
-
PATH configuration issue.
Solution:
-
Install the JDK (not just a runtime).
-
Verify the installation using the installation directory.
Problem 3: Wrong Java Version
Solution:
-
Remove old Java versions if necessary.
-
Install the latest JDK.
-
Verify using:
java -version
Best Practices
-
Install the latest Long-Term Support (LTS) version of Java whenever possible.
-
Download Java only from official sources.
-
Keep your JDK updated.
-
Avoid installing multiple Java versions unless required.
Key Points to Remember
-
The JDK is required to develop Java applications.
-
The
javacommand checks the Java Runtime. -
The
javaccommand checks the Java Compiler. -
Always verify your installation before writing Java programs.
-
The PATH variable allows Java commands to run from any location.
Lesson Summary
In this lesson, you learned:
-
What the Java Development Kit (JDK) is.
-
How to download and install the JDK.
-
How to verify the installation.
-
The purpose of the PATH environment variable.
-
Common installation problems and their solutions.
Your system is now ready to start writing and running Java programs.
Practice Questions
-
What is the JDK?
-
Why do we need to install the JDK?
-
Which command checks the Java Runtime version?
-
Which command checks the Java Compiler version?
-
What is the purpose of the PATH environment variable?
-
What should you do if
javais not recognized?
Assignment
Complete the following tasks:
-
Install the Java Development Kit on your computer.
-
Verify the installation using:
-
java -version -
javac -version
-
-
Take a screenshot of the successful output.
-
Create a folder named Java Practice that will be used throughout this course.