๐ŸŽ‰ Special Offer !    Code: GET300OFF    Flat โ‚น300 OFF on every Java Course
Grab Deal ๐Ÿš€

JAVA_HOME vs Java Path  


Difference between JAVA_HOME and Java Path

The difference between JAVA_HOME and the Path environment variable for Java lies in their purpose and usage. Both are related to setting up Java on your system, but they serve different functions.

  • 1. JAVA_HOME
    • Purpose : JAVA_HOME is an environment variable used to specify the installation directory of the Java Development Kit (JDK). It points to the root folder where Java is installed.
    • Usage : This variable is typically used by Java-based applications, tools, or scripts to locate the Java installation on our machine. It's required by many development tools, including Maven, Gradle, and certain Java IDEs like Eclipse or IntelliJ IDEA.
    • Example : If we have JDK installed in C:\Program Files\Java\jdk-17, then JAVA_HOME should be set to this directory.
    • Setting JAVA_HOME :
      • Windows:
        • Go to Control Panel > System and Security > System > Advanced system settings > Environment Variables.
        • Under System variables, click New and set the variable name as JAVA_HOME and the value as C:\Program Files\Java\jdk-17.
      • Linux/Mac:
        • We can set JAVA_HOME in our shell configuration file (like ~/.bashrc, ~/.bash_profile, or ~/.zshrc):
        • export JAVA_HOME=/usr/lib/jvm/java-17-openjdk
  • 2. Java Path (or PATH)
    • Purpose : The Path environment variable is used to tell the operating system where to look for executable files, such as java and javac. It doesn't directly point to the JDK installation but includes the bin folder inside the JDK directory.
    • Usage : When we run commands like java or javac from the command line, the system looks through the directories listed in the Path variable to find these executables. By adding the JDK's bin directory to Path, we can run Java commands from any directory in the terminal or command prompt.
    • Example : If our JDK is installed in C:\Program Files\Java\jdk-17, the Path variable should include C:\Program Files\Java\jdk-17\bin.
    • Setting Path :
      • Windows:
        • Go to Control Panel > System and Security > System > Advanced system settings > Environment Variables.
        • Under System variables, find and edit the Path variable. Add a new entry like: C:\Program Files\Java\jdk-17\bin.
      • Linux/Mac:
        • We can add the bin directory to the PATH in our shell configuration file:
        • export PATH=$JAVA_HOME/bin:$PATH

Difference between JAVA_HOME & Java Path
Feature JAVA_HOME Path
Purpose Points to the Java installation directory (JDK or JRE). Specifies directories where the operating system looks for executable files (e.g., java, javac).
Usage Used by Java tools, IDEs, and build systems (e.g., Maven, Gradle). Used to run commands like java, javac from anywhere in the terminal/command prompt.
Where It's Set Set to the root folder of the JDK installation (e.g., C:\Program Files\Java\jdk-17). Points to the bin folder inside the JDK or JRE directory (e.g., C:\Program Files\Java\jdk-17\bin).
Example JAVA_HOME=C:\Program Files\Java\jdk-17 Path=C:\Program Files\Java\jdk-17\bin
Required For Required by tools and scripts to locate the JDK installation. Required to run Java commands (like java or javac) from the command line.