Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Black Friday 2026 – NPI EA – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

1. Overview

In this tutorial, we’ll explore the key difference between using JAVA_HOME and PATH environment variables. Though most Java programs need both these variables to compile and run successfully, each serves a different purpose. Let’s see them one by one.

2. JAVA_HOME Environment Variable

The JAVA_HOME environment variable points to the JDK installation directory. Subsequently, other Java-dependent programs can use this variable to access the JDK/JRE path.

In general, Apache Tomcat and other Java EE application servers, along with build tools such as Maven or Gradle, use JAVA_HOME as a naming convention to locate Java.

In most cases, JAVA_HOME is set to point to the JDK path instead of the JRE. This is useful for modern development tools that need access to the compiler, debugger, document generator, etc.

Here’s how we set the JAVA_HOME variable through the command-line:

set JAVA_HOME=C:\Program Files\Java\jdk-17

Alternatively, we can also set this variable through system settings. Windows users can find this setting under the System Properties -> Advanced -> Environment Variables.

3. PATH Environment Variable

The operating system uses the PATH environment variable to find the native executable programs to run.

In Windows, the executable programs end with a .exe extension. Once we point the executable program’s directory in PATH, we can invoke the same in the command-line without the need to specify its full path.

For Java programs to run, we need to list the JDK installation directory along with the bin directory in the PATH variable. The bin directory holds the Java executables.

We can set the PATH environment variable through the command-line:

set PATH=C:\Program Files\Java\jdk-17\bin

As seen in the previous section, we can achieve the same through the system settings. Typically, the PATH variable contains multiple paths pointing to different directories. As such, this setting is not limited to Java.

4. Using JAVA_HOME and PATH Together

Modern programs are intelligent enough to pick one of the JAVA_HOME or PATH variables to run successfully. However, a few other programs, such as Eclipse, need the PATH variable to startup.

As a best practice, setting both the JAVA_HOME and PATH environment variables is always recommended. This way, we can remove the compatibility issues between using old and new programs.

Also, to avoid repeating the JDK installation path twice, we can reuse one of these variables in the declaration:

set PATH=%JAVA_HOME%\bin;%PATH%

As a result, this setting also removes the risk of changing all the affected environment variables when there’s a change in the JDK installation directory.

5. Common Problems

Certain programs rely on specific variables for startup. For instance, if JAVA_HOME isn’t set, the programs that rely on this variable may not locate the JDK.

Subsequently, programs such as Tomcat, Maven, and Gradle may not execute properly. Likewise, the same issue applies to the programs which rely on the PATH variable.

Specifically, when we try to run a Java program from the command-line, the operating system looks into the PATH variable to locate and run the JVM. If there’s no JDK on the PATH variable, the command terminates with an error:

C:\Users\palan>java HelloWorld
'java' is not recognized as an internal or external command,
operable program or batch file.

Another common issue is having different JDK versions in the PATH variable. In such a case, the operating system considers the first occurrence of JDK in the PATH variable for execution. However, it’s better to remove multiple versions in the PATH variable to avoid confusion at a later stage.

6. Conclusion

In this article, we explored the differences between using the JAVA_HOME and PATH environment variables.

To conclude, the JAVA_HOME environment variable is used by programs mostly targeted as development tools. On the other hand, user-facing applications need the PATH environment variable to know the location of the JVM.

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2026 – NPI EA – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

2 Comments
Oldest
Newest