A Complete Guide - Setting up Java Environment JDK, JRE

Last Updated: 03 Jul, 2025   
  YOU NEED ANY HELP? THEN SELECT ANY TEXT.

Setting Up a Java Environment: JDK vs. JRE

1. Understanding the Components

  • JDK (Java Development Kit):

    • Purpose: The JDK includes tools essential for Java development such as compilers, debuggers, and utility classes. It is used for writing, compiling, and debugging Java programs.
    • Key Tools:
      • javac: Compiles Java source files into bytecodes.
      • java: Runs the Java Virtual Machine (JVM) on a class file.
      • javadoc: Generates HTML documentation from doc comments in Java source code.
      • jar: Packages Java classes into JAR files.
      • javap: Disassembles class files to view Java bytecode.
      • Others include jdb, jconsole, jvisualvm.
  • JRE (Java Runtime Environment):

    • Purpose: The JRE provides the runtime environment necessary to execute Java applications. It includes the JVM, core libraries, and other runtime essentials.
    • Key Components:
      • JVM (Java Virtual Machine): Translates Java bytecode into native machine instructions.
      • Core Libraries: Java libraries that provide utilities and functions needed by applications.
      • Security Manager: Ensures secure execution of Java code.

2. Download and Install the JDK

To start Java development:

Verify the JRE installation by running java -version.

5. Important Information

Step-by-Step Guide: How to Implement Setting up Java Environment JDK, JRE


Setting Up Java Environment: JDK and JRE

1. Understand the Basics

  • JDK (Java Development Kit):
    This includes tools necessary for developing Java applications, such as:
    • javac: The Java compiler.
    • javap: A tool to disassemble class files.
    • javadoc: A tool for generating API documentation in HTML format.
  • JRE (Java Runtime Environment):
    This is a superset of the Java Virtual Machine (JVM) and its associated libraries, necessary to run Java applications. The JDK includes the JRE.

2. Download the JDK

  1. Visit the Official Oracle Website:

  2. Verify the Installation:

    • Open Terminal.
    • Type javac -version and press Enter.
    • Type java -version and press Enter.
    • Both commands should display the version numbers of the JDK and JRE, confirming a successful installation.

For Linux:

  1. Download the JDK:

    • If using a web browser, you can download directly. For automated downloads, you might use wget:
      wget 
  2. Extract the Archive:

    • Open Terminal.
    • Navigate to the directory containing the .tar.gz file.
    • Extract the archive using tar:
      sudo tar zxvf jdk-x_linux-x64_bin.tar.gz -C /opt/
      
  3. Set the JAVA_HOME Environment Variable:

    • Open Terminal.
    • Open the .bashrc or .profile file in a text editor (e.g., nano ~/.bashrc).
    • Add the following lines:
      export JAVA_HOME=/opt/jdk-x
      export PATH=$JAVA_HOME/bin:$PATH
      
    • Save the file and exit the editor.
    • Reload the profile by running source ~/.bashrc.
  4. Verify the Installation:

    • Open Terminal.
    • Type javac -version and press Enter.
    • Type java -version and press Enter.
    • Both commands should display the version numbers of the JDK and JRE, confirming a successful installation.

4. Compile and Run a Simple Java Program

  1. Create a Java File:

    • Open a text editor (e.g., Notepad, Visual Studio Code, Sublime Text).
    • Enter the following simple Java program:
      public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); }
      }
      
    • Save the file as HelloWorld.java.
  2. Compile the Java Program:

    • Open Command Prompt (Windows), Terminal (macOS/Linux).
    • Navigate to the directory containing HelloWorld.java.
    • Compile the program using javac:
      javac HelloWorld.java
      
    • This will generate a HelloWorld.class file in the same directory.
  3. Run the Compiled Program:

    • Run the program using java:
      java HelloWorld
      
    • You should see the output:
      Hello, World!
      

5. Install an Integrated Development Environment (IDE) (Optional)

Login to post a comment.