Find Java Location in Windows

Rupam Yadav Jan 30, 2023 May 14, 2021
  1. Find Java Location Using Command where java
  2. Find Java Location Using Command set JAVA_HOME
  3. Find Java Location Using Command dir /b /s java.exe
  4. Find Java Location Using Command gcm -All java in Windows PowerShell
Find Java Location in Windows

Today, we will see how to find out where Java is located in Windows. There are multiple ways and commands to do this; we will check out various commands that return the Java location windows.

Find Java Location Using Command where java

The most commonly used command to get the current location of Java in Windows is where java. This is a Windows command that works just like the whereis command in Linux Operating System. The where command is used to display the location of the executable. It usually uses a search pattern.

As shown below, when we run the command where java in the command line of Windows, it returns the location of java.exe.

C:\User > where java



Find Java Location Using Command set JAVA_HOME

The next technique to get the location of Java in Windows is to use the command set JAVA_HOME. In Windows, the path of Java or JDK is stored in the environment variables. The location is stored in the variable named PATH, a list of directories that can be used to access certain programs like Java directly without writing the whole path.

We can set the path of Java by the command set JAVA_HOME and then specify the path. But if the value is already set, it will return the path set to the variable JAVA_HOME. It completes our goal as this is the directory in which Java is located.

C:\Users\Rupam Saini>set JAVA_HOME


JAVA_HOME=C:\Users\Rupam Saini\.jdks\openjdk-15.0.1

Find Java Location Using Command dir /b /s java.exe

The dir command shows all the folders and sub-folders in the current location. We can use this command to get the locations of Java as there might be more than one executable of Java in a single Windows machine as some programs use their own Java environment.

We use the dir command with three parameters, first is /b that displays only the directory path without any extra details. In contrast, the /s parameter lists every occurrence of the specified file in the current directory and subdirectories, and at last, the execute name that is java.exe.

C:\User>dir /b /s java.exe	


C:\User\AppData\Local\JetBrains\IntelliJ IDEA Community Edition 2020.3\jbr\bin\java.exe

Find Java Location Using Command gcm -All java in Windows PowerShell

In all the examples in this tutorial, we use the traditional command-line,, but this method requires the Windows PowerShell, a command-line but with advanced capabilities. In PowerShell, we use the gcm command that is short for get-command. It returns all the commands in the machine.

We use gcm with two parameters; the first is -All that shows all the instances of the command in the current machine, and the second parameter is the command name. In our case, the command name is java. In return, it outputs some details about the command like the Command Type, the name of the executable executed on command, the version, and the executable source. The source is where Java is located.

PS C:\User> gcm -All java


CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     java.exe                                    C:\User\.jdks\openjdk-15...
Author: Rupam Yadav
Rupam Yadav avatar Rupam Yadav avatar

Rupam Saini is an android developer, who also works sometimes as a web developer., He likes to read books and write about various things.