Paramclasses Academy - Blog

Tutorials Details

←
Post 3 of 15
→

How to Install Java JDK and Set Up Your First Java Program

How to Install Java JDK and Set Up Your First Java Program

October 21, 2026

Introduction

Before writing Java programs, you need to set up a Java development environment on your computer.

The Java Development Kit (JDK) provides the compiler and development tools required to write, compile, and run Java applications.

In this tutorial, you will learn how to download and install the JDK, verify the installation, configure environment variables if necessary, and create your first Java program step by step.

This guide focuses on Windows because it is a common environment for beginners. The official documentation also provides installation instructions for macOS and Linux.

What Do You Need to Install Java?

Before starting, make sure you have:

  • A Windows computer.

  • An internet connection to download the JDK.

  • Permission to install software on your computer.

  • A text editor such as Notepad or a code editor such as Visual Studio Code.

You do not need a separate JRE installation to begin learning Java. A JDK provides the tools and runtime components needed for standard Java development.

Step 1: Download Java JDK

First, download a JDK distribution from a trusted source.

You can choose Oracle JDK or another reputable OpenJDK distribution, such as Eclipse Temurin or Microsoft Build of OpenJDK. Check the relevant distribution's licensing and support terms if you plan to use it commercially.

Official download links:

Which JDK Version Should Beginners Choose?

Choose a currently supported Long-Term Support (LTS) JDK for learning and compatibility with courses or projects. Java 21 and Java 25 are examples of LTS releases; check the selected distribution's current support information before installing.

For this tutorial, the installation steps are broadly similar across modern JDK versions.

Download Instructions

  1. Open one of the official download pages.

  2. Select Windows as your operating system.

  3. Choose the installer that matches your computer's architecture, such as x64 or ARM64.

  4. Download the installer.

  5. Wait for the download to finish before opening the file.

Important: Download Java only from a trusted official source. Avoid unfamiliar download websites.

Step 2: Install Java JDK on Windows

After downloading the installer, follow these steps.

  1. Open your Downloads folder.

  2. Double-click the downloaded JDK installer.

  3. Approve the installation prompt if Windows asks for permission.

  4. Follow the installer instructions.

  5. Keep the default installation location unless you have a specific reason to change it.

  6. Finish the installation.

A common installation directory for Oracle JDK is:

C:\Program Files\Java\

The exact folder name depends on the JDK distribution and version.

After installation, the JDK directory should contain a bin folder with tools such as java.exe and javac.exe.

Step 3: Check Whether Java Is Installed

Now verify the installation using the Windows Command Prompt.

Open Command Prompt

  1. Press Windows + R.

  2. Type cmd.

  3. Press Enter.

Check the Java Runtime

Run this command:

java -version

If Java is installed and configured correctly, the terminal displays version information for the Java runtime.

The exact output depends on the installed distribution and version.

Check the Java Compiler

Next, run:

javac -version

This command checks whether the Java compiler is available.

If both commands work, you are ready to create and compile Java programs.

If Windows reports that a command is not recognized, continue to the environment configuration section below.

Step 4: Configure JAVA_HOME and PATH

Some JDK installers configure command-line access automatically. If java or javac is not recognized, you may need to configure the environment variables.

What Is JAVA_HOME?

JAVA_HOME is an environment variable that points to the JDK installation directory. Development tools such as Maven and Gradle commonly use it to locate Java.

For example, your JDK directory might be:

C:\Program Files\Java\jdk-21

Use your actual installation directory rather than copying this example blindly.

How to Set JAVA_HOME

  1. Open the Windows Start menu.

  2. Search for Edit the system environment variables.

  3. Open the System Properties window.

  4. Select Environment Variables.

  5. Under User variables, select New.

  6. Enter the following:

Variable name:

JAVA_HOME

Variable value:

C:\Program Files\Java\jdk-21
  1. Replace the example path with your actual JDK folder.

  2. Save the variable.

How to Add Java to PATH

  1. In the Environment Variables window, select the Path variable under User variables.

  2. Click Edit.

  3. Add a new entry:

%JAVA_HOME%\bin
  1. Save the changes and close the dialogs.

  2. Open a new Command Prompt window.

Now run:

java -version
javac -version

If both commands display version information, command-line access is configured correctly.

Note: Do not replace your existing PATH entries. Add a new entry instead.

Step 5: Write Your First Java Program

Now that the JDK is installed, create your first Java program.

We will write a program that prints a welcome message.

Create a Java File

  1. Open Notepad or your preferred code editor.

  2. Enter the following code:

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
  1. Save the file as:

Main.java

If you use Notepad, select Save as type: All Files and ensure that the filename is Main.java, not Main.java.txt.

Understanding the Code

public class Main

This declares a class named Main. The filename must match the public class name, including capitalization.

public static void main(String[] args)

This is the main method used as the entry point when launching this standard Java application.

System.out.println()

This statement prints the specified text to the console and then moves to a new line.

"Hello, World!"

This is the text displayed when the program runs.

Step 6: Compile the Java Program

Open Command Prompt and navigate to the folder where you saved Main.java.

For example, if the file is saved on your Desktop:

cd "%USERPROFILE%\Desktop"

Now compile the program:

javac Main.java

If compilation succeeds, Java creates a file named:

Main.class

This file contains the compiled Java bytecode.

If an error appears, check the filename, class name, punctuation, and JDK installation.

Step 7: Run Your First Java Program

In the same folder, execute:

java Main

Expected output:

Hello, World!

Congratulations! You have written, compiled, and executed your first Java program.

Notice that you run the class using java Main, without adding .java or .class to the class name.

Complete Java Program Workflow

The process can be summarized as follows:

Write Java Code
      |
      v
Save as Main.java
      |
      v
Compile with javac
      |
      v
Generate Main.class
      |
      v
Run with java Main
      |
      v
Display Output

The compiler converts Java source code into bytecode, and the Java runtime executes the compiled program.

Common Java Installation Errors and Solutions

1. 'java' Is Not Recognized

Cause: The Java launcher may not be installed or available through PATH.

Solution: Verify the JDK installation and configure PATH if needed. Open a new terminal after changing environment variables.

2. 'javac' Is Not Recognized

Cause: The JDK compiler may not be installed or the JDK's bin directory may not be included in PATH.

Solution: Install a JDK and check that %JAVA_HOME%\bin points to the correct directory.

3. Could Not Find or Load Main Class

Cause: The terminal may be in the wrong folder, or the class name may be incorrect.

Solution: Navigate to the directory containing Main.class and run:

java Main

Check capitalization carefully.

4. Class Main Is Public, Should Be Declared in a File Named Main.java

Cause: The filename does not match the public class name.

Solution: Save the source file as Main.java.

5. Error: File Not Found

Cause: The terminal is not in the folder containing the source file, or the filename is incorrect.

Solution: Use the cd command to navigate to the correct folder and check that Main.java exists.

Is an IDE Required to Learn Java?

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

However, an Integrated Development Environment (IDE) can make development easier by providing code completion, syntax highlighting, debugging tools, and project management.

Popular options include:

Beginners can start with the command line to understand how Java compilation works, then move to an IDE when they are comfortable.

Practice Exercises for Beginners

Try these exercises after completing the tutorial.

  1. Write a Java program that prints your name.

  2. Display your name, course, and college on separate lines.

  3. Print the result of adding two numbers.

  4. Change the welcome message to Welcome to PARAM WEB INFO!.

  5. Create a class named Student in a file named Student.java and print a message from its main method.

Practising these small programs will help you become comfortable with Java syntax and the compile-and-run workflow.

Frequently Asked Questions (FAQs)

1. Is Java free to download?

Several JDK distributions are available without charge, but licensing terms vary by distribution, version, and use case. Review the applicable license before commercial deployment.

2. Can I learn Java without installing an IDE?

Yes. A JDK, a text editor, and the command line are enough to write, compile, and run simple Java programs.

3. What is the difference between java and javac?

javac compiles Java source files into bytecode. The java command launches Java applications.

4. Why is the file named Main.java?

In this example, the public class is named Main, so the source file must be named Main.java. Java identifiers and filenames are case-sensitive in this context.

5. Do I need to configure JAVA_HOME?

Not every Java setup requires it. However, many development tools use JAVA_HOME to locate the JDK, so configuring it can be helpful.

6. Can I run Java programs on Windows 11?

Yes. A compatible JDK can be installed and used on supported Windows 11 systems. Follow the selected JDK distribution's system requirements.

7. What should I learn after installing Java?

Start with variables and data types, operators, type casting, conditional statements, loops, arrays, strings, and methods.

Conclusion

Installing the Java JDK is the first practical step toward learning Core Java. Once the JDK is installed and configured, you can write source code, compile it with javac, and execute it with the Java launcher.

Practise the commands and exercises in this tutorial until you can run a simple program without assistance.

 

←
Post 3 of 15
→