INSTALLATION OF JDK

Introduction :


The Java Development Kit (JDK) is a set of software tools for developing Java applications. The toolkit includes a compiler for converting Java code into bytecode, a collection of class libraries, documentation for integrating Java APIs, and the Java Runtime Environment (JDE) for executing Java code.
The JDK provides developers the resources they need to create Java applications and applets in one neat package.


Find How To Install Java Development Kit on Windows :


Check If Java Is Installed :
Multiple Java versions on the same system can cause conflicts, as applications may attempt to use different versions. Additionally, outdated versions can pose significant security risks over time.
Before installing the latest Java Development Kit, check if a Java version is already installed on Windows:
  1. Type cmd in the Windows search bar.
  2. Open the command prompt.
  3. jdk-1

  4. Enter the following command to check the Java version in Windows:
  5. 
        java -version
    
    jdk-2

    In this example, the message states that Java is not recognized as an internal or external command, which indicates that Java is not installed. If the system displays a Java version number, remove the old Java installation before proceeding.

Download Java for Windows :


OpenJDK is an open-source project that provides source code for implementing the Java platform. Many companies, including Oracle, offer distributions of OpenJDK in the form of installers or binaries.
To download the latest Java Development Kit installation file for Windows:
  1. Open a web browser and navigate to the Oracle Java Downloads page through given link JDK Download
  2. Select the latest JDK version. In this example, the latest available version is JDK 21.
  3. Access the Windows tab.
  4. Click the x64 Installer download link.
  5. jdk-4

    Wait for the download to complete.

Install Java on Windows :


To install Java on your Windows system :
  1. Double-click the downloaded Java file to start the installation.
  2. Once the installation wizard welcome screen appears, select Next to proceed.
  3. jdk-5

  4. Now click Next to see the below image, Here you have a choice to change the Java installation directory by clicking on the change… button otherwise simply go with the default path by clicking the Next > button. I am going here with the default path only. Now it will start to install.
  5. jdk-6

    jdk-7

    You have successfully installed JDK 21 on your Windows system. To enable program compiling from any directory, you must set up Java environment variables.

Set Environmental Variables in Java :


Follow the steps in the sections below to configure Java environment variables in Windows.
Step 1 : Add Java to System Variables
This step ensures that Java is accessible from the command line in any directory.
  1. Open the Start menu and search for environment variables.
  2. Select Edit the system environment variables.
  3. jdk-8

  4. Select Advanced in the System Properties window.
  5. Click Environment Variables.
  6. jdk-9

  7. Select the Path variable in the System variables category and click Edit.
  8. jdk-10

  9. Click New.
  10. Enter the path to the Java bin directory.
  11. Click OK to save the changes and exit the variable editing window.
  12. jdk-11

Note : The default path for JDK 21 is C:\Program Files\Java\jdk-21\bin.

Step 2 : Add JAVA_HOME Variable
Some applications require the JAVA_HOME variable to point to the JDK installation directory. Follow the steps below to create the variable:
  1. Click New under the System variables category to create a new variable.
  2. jdk-12

  3. Name the variable JAVA_HOME.
  4. Enter the path to your Java JDK directory in the variable value field.
  5. Click OK.
  6. jdk-13

    Confirm the changes by clicking OK in the Environment Variables and System properties windows.


Test Java Installation :


Verify that Java is installed by entering the java -version command in the command prompt: jdk-14

If installed correctly, the command outputs the Java version. To ensure everything works, write and compile a simple Java program by following the steps in the sections below.

Step 1: Write Test_Java
  • Open a text editor like Notepad or Notepad++ and create a new file.
  • Enter the following code and click Save:
  •     class Test_Java{
            public static void main(String args[]){
                System.out.println("Hello world!");
            }
        }
    
    
    jdk-15

    Note : When using Notepad, select All files for the Save as type option and add the .java extension to the file name.

    Step 2: Compile Test Java Script
    Access the Windows command prompt and complete the following steps:
    1. Navigate to the directory where your Java file is saved.
    2. Use the following command to compile the program:
    
        javac Test_Java.java
    
    jdk-16

    After a successful compilation, the program generates a .class file in the same directory.
    Run the program using the following syntax:
    
        java Test_Java
    
    The output shows that the program runs correctly, displaying the Hello world! message.


    Conclusion :


    This tutorial showed how to install the Java Development Kit on a Windows system.


    ☛ Join to Learn from Experts: Java / J2EE Training in Chennai by TesDBAcademy
    (Installation - Eclipse IDE)