How to Find Java Virtual Machine DLL
This tutorial will introduce how to know where JDK/JRE is installed to find the Java location to access the jvm.dll
file.
How to Find Java Virtual Machine DLL
Java must be installed on the machine to find the Java Virtual Machine dll file. Sometimes, we are stuck in work so much and start searching for the jvm.dll
file before installing Java.
It is better to check whether we have Java installed on our machine or not to avoid that kind of situation. We can write the following command on the command line prompt (cmd).
C:\Users\Dell> java -version
It tells the version of Java that we installed, otherwise, produces the following error.
'java' is not recognized as an internal or external command,
operable program or batch file.
Once we know that we’ve installed Java on our machine, the next move is finding the path to access the jvm.dll
file.
We can install Java anywhere on the machine. So, it is difficult to specify one exact path where we can find the Java Virtual Machine dll file (jvm.dll
).
But if you have installed it on its default location, then the Java
folder must reside in the C:\Program Files
folder drive, which further helps you find the jvm.dll
file.
We know that JDK and JRE can be installed in different locations, which means you can also have a custom path. Remember, the jvm.dll
always resides in your_path\bin\client
and your_path\bin\server
for JRE and JDK, respectively.
We have used the default location for JRE installation and the custom location for JDK; both paths are given below.
- The
jvm.dll
file path for JRE:C:\Program Files (x86)\Java\jre1.8.0_241\bin\client
- The
jvm.dll
file path for JDK:C:\Java\jdk-17.0.2\bin\server
What if we don’t even remember the path where we have installed Java? Now, how will you find the jvm.dll
file?
Do we have any time-saving solution rather than wondering in various folders to find Java location to get the jvm.dll
file? Yes, some of them are given below.
Different Approaches to Find Java Location for jvm.dll
We can use the following methods to find the Java location for the jvm.dll
file.
Use for %i in (java.exe) do @echo. %~$PATH:i
to Find Java Location
Here, we use a loop and specify the file’s name that we are looking for in the path. We are looking for java.exe
in the command given below.
C:\Users\Dell> for %i in (java.exe) do @echo. %~$PATH:i
Output:
C:\Program Files\Common Files\Oracle\Java\javapath\java.exe
Use where java
to Find Java Location
The simplest and easiest command to find Java location in Windows Operating System is where java
. It uses the search pattern and displays the executable’s location.
As soon as we run the following command in the Windows Command-Line, it displays the java.exe
’s location on the command line.
C:\Users\Dell> where java
Output:
C:\Program Files\Common Files\Oracle\Java\javapath\java.exe
C:\Java\jdk-17.0.2\bin\java.exe
Use getProperty()
to Find Java Location
We can also use the getProperty()
method to find a Java location to access the jvm.dll
file. This method takes one parameter, a key
and returns its value.
In the following program, we are trying to access the value of java.home
, a Java location path.
Example Code:
public class Test {
public static void main(String[] args) {
System.out.println(System.getProperty("java.home"));
}
}
Output:
Use dir /b /s java.exe
to Find Java Location
This command is time-consuming compared to the other commands given in this tutorial because it displays the current locations of all the folders & sub-folders. We can also use this command to find Java locations, specifically when we have multiple Java executables on one machine.
The /b
in the following command shows the directory path only and excludes all extra details, while /s
lists all occurrences of the given file (java.exe
for this tutorial) in the current directory & sub-directories.
C:\Users\Dell> dir /b /s java.exe
Output:
C:\Users\DelftStack\.vscode\extensions\redhat.java-1.4.0\jre\17.0.2-win32-x86_64\bin\java.exe
Use gcm -All java
to Find Java Location
Do you also like to use Windows PowerShell instead of the traditional Windows command prompt? Then, you can use the gcm -All java
/get-command -All java
(both are the same) command on Windows PowerShell to find the Java location.
The get-command
, also written as gcm
, returns all commands in a machine. Specifying -All java
will return all the instances of the java
with some extra details.
Here, we get CommandType
, Name
, Version
, and the Source
where Java resides.
PS C:\Users> gcm -All java
Output:
Use Environment Variable
to Find Java Location
The Java location can also be identified from the Environment Variable
. See the following instructions.
Once you get the Java path, you can easily find the jvm.dll
file.