BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

How to set Path in Java

Last Updated: May 26, 2024 by Chaitanya Singh | Filed Under: java

In this article, we will learn how to set path in java. Setting path in Windows allows you to run Java applications and compile Java code from the command line, without specifying the full path to the Java executable. Here’s how you can do it:

Step-by-Step Guide:

  1. Download and Install Java Development Kit (JDK):
    • The first step is to download and install JDK, download it from the Oracle website or OpenJDK site.
    • Install the JDK.
  2. Find the JDK Installation Path:
    • After installation, find the folder where the JDK is installed. Usually, it looks like C:\Program Files\Java\jdk-xx.x.x.
  3. Open Environment Variables:
    • Press Win + X and select System or System settings.
    • In System settings, click on Advanced system settings on the left-hand side.
    • In the System Properties window, click on the Environment Variables button.
  4. Set JAVA_HOME:
    • In the Environment Variables window, click on the New button under the System variables section.
    • Enter JAVA_HOME as the Variable name.
    • Enter the JDK installation path (e.g., C:\Program Files\Java\jdk-xx.x.x) as the Variable value.
    • Click OK.
  5. Update the PATH Variable:
    • In the Environment Variables window, find the Path variable in the System variables section and select it.
    • Click on the Edit button.
    • In the Edit Environment Variable window, click on the New button and add the following: %JAVA_HOME%\bin
    • Click OK to close all windows.
  6. Verify the Setup:
    • Open a new Command Prompt window (press Win + R, type cmd, and press Enter).
    • Type the following command and press Enter: java -version
    • If the path is set correctly, you should see java version information. This confirms that everything is setup correctly.

Summary of Commands and Entries:

JAVA_HOME:

Variable name: JAVA_HOME
Variable value: C:\Program Files\Java\jdk-xx.x.x

Path:

%JAVA_HOME%\bin

Example:

Let’s say, you installed JDK version 15.0.2 in the default directory, the entries would be:

JAVA_HOME:

Variable name: JAVA_HOME
Variable value: C:\Program Files\Java\jdk-15.0.2

Path:

%JAVA_HOME%\bin

Once these steps are completed, your path is permanently set in Windows. You can compile and run Java programs without needing to specify the full path to the Java executables.

Top Related Articles:

  1. C++ vs Java – Difference between C++ and Java
  2. Java Virtual Machine (JVM)
  3. Nested or Inner interfaces in Java
  4. Java 9 JShell (Java Shell) – REPL
  5. Constructor Overloading in Java with examples

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Java Tutorial

Java Introduction

  • Java Index
  • Java Introduction
  • History of Java
  • Features of Java
  • C++ vs Java
  • JDK vs JRE vs JVM
  • JVM - Java Virtual Machine
  • First Java Program
  • Variables
  • Data Types
  • Operators

Java Flow Control

  • Java If-else
  • Java Switch-Case
  • Java For loop
  • Java while loop
  • Java do-while loop
  • Continue statement
  • break statement

Java Arrays

  • Java Arrays

OOPs Concepts

  • OOPs Concepts
  • Constructor
  • Java String
  • Static keyword
  • Inheritance
  • Types of inheritance
  • Aggregation
  • Association
  • Super Keyword
  • Method overloading
  • Method overriding
  • Overloading vs Overriding
  • Polymorphism
  • Types of polymorphism
  • Static and dynamic binding
  • Abstract class and methods
  • Interface
  • Abstract class vs interface
  • Encapsulation
  • Packages
  • Access modifiers
  • Garbage Collection
  • Inner classes
  • Static import
  • Static constructor

Java Exception Handling

  • Exception handling
  • Java try-catch
  • Java throw
  • Java throws
  • Checked and Unchecked Exceptions
  • Jav try catch finally
  • Exception Examples
  • Exception Propagation

Collections Framework

  • Collections in Java
  • Java ArrayList
  • Java LinkedList
  • Java Vector
  • Java HashSet
  • Java LinkedHashSet
  • Java TreeSet
  • Java HashMap
  • Java TreeMap
  • Java LinkedHashMap
  • Java Queue
  • Java PriorityQueue
  • Java Deque
  • Comparable interface
  • Comparator interface
  • Collections Interview Questions

MORE ...

  • Java Scanner Class
  • Java 8 Features
  • Java 9 Features
  • Java Conversion
  • Java Date
  • Java Multithreading
  • Java I/O
  • Java Serialization
  • Java Regex
  • Java AWT
  • Java Swing
  • Java Enum
  • Java Annotations
  • Java main method
  • Java Interview Q

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap