To get your jdk location in Windows, run this at a command prompt:
where java
This lists any and all locations of java.exe, including from your JAVA_HOME. For example, the 3rd line here reflects my JAVA_HOME location, where I’m pointing to JDK 8:
C:\Users\me> where java
C:\Program Files\Common Files\Oracle\Java\javapath\java.exe
C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe
C:\Program Files\Java\jdk1.8.0_202\bin\java.exe
Note for comparison that java -version
does not reflect my JAVA_HOME location and in fact shows java version 11 instead of 8:
C:\Users\me> java -version
java version "11.0.15" 2022-04-19 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.15+8-LTS-149)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.15+8-LTS-149, mixed mode)
This is confusing because my Java compiles (e.g., via mvn) use JDK 8 since that’s what my JAVA_HOME is pointing to. (I’m not even sure where the version 11 it found came from; possibly from when I installed maven.)
Determining the difference between the JRE and JDK you’re running has never been straightforward. Seems like java -version used to be a way to do this, but no longer.
Adding to the complexity, you can also supposedly get your Java version info from Control Panel > Programs > Java > About. For me, that shows Version 8. That’s despite java -version showing version 11.0.15. And it doesn’t change even if I point my JAVA_HOME to JDK 11.
Note that this answer is also helpful. In my case, that helped me determine that I have java.exe and javac.exe at C:\Program Files (x86)\Common Files\Oracle\Java\javapath
and C:\Program Files\Common Files\Oracle\Java\javapath
. Depending on which one I have listed first in my Path variable, I get different results when i run java -version
or java --version
. The former seems to work when Java 8 is listed first; the latter when Java 11 is first.
To get your jdk location in Windows, run this at a command prompt:
where java
This lists any and all locations of java.exe, including from your JAVA_HOME. For example, the 3rd line here reflects my JAVA_HOME location, where I’m pointing to JDK 8:
C:\Users\me> where java
C:\Program Files\Common Files\Oracle\Java\javapath\java.exe
C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe
C:\Program Files\Java\jdk1.8.0_202\bin\java.exe
Note for comparison that java -version
does not reflect my JAVA_HOME location and in fact shows java version 11 instead of 8:
C:\Users\me> java -version
java version "11.0.15" 2022-04-19 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.15+8-LTS-149)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.15+8-LTS-149, mixed mode)
This is confusing because my Java compiles (e.g., via mvn) use JDK 8 since that’s what my JAVA_HOME is pointing to. (I’m not even sure where the version 11 it found came from; possibly from when I installed maven.)
Determining the difference between the JRE and JDK you’re running has never been straightforward. Seems like java -version used to be a way to do this, but no longer.
Adding to the complexity, you can also supposedly get your Java version info from Control Panel > Programs > Java > About. For me, that shows Version 8. That’s despite java -version showing version 11.0.15. And it doesn’t change even if I point my JAVA_HOME to JDK 11.
Note that this answer is also helpful. In my case, that helped me determine that I have java.exe and javac.exe at C:\Program Files (x86)\Common Files\Oracle\Java\javapath
and C:\Program Files\Common Files\Oracle\Java\javapath
. Depending on which one I have listed first in my Path variable, I get different results when i run java -version
or java --version
. The former seems to work when Java 8 is listed first; the latter when Java 11 is first.
Комплект для разработки Java (JDK) содержит инструменты для разработки Java, а Среда выполнения Java (JRE) содержит JVM для преобразования байтового кода .class
для машинного кода и его выполнения, короче говоря, JRE запускает программу Java.
Проверьте версию JDK Мы можем использовать
java-версию чтобы узнать версию установленного JDK. В приведенном ниже примере версия JDK равна
$ javac -version javac 11.0.7
Проверьте версию JRE Мы можем использовать java-версию
, чтобы узнать версию установленной JRE. В приведенном ниже примере версия JRE равна 1.8.0_252
$ java -version openjdk version "1.8.0_252" OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1~19.10-b09) OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
Версии JDK и JRE могут отличаться на одном компьютере. На одном компьютере разрешено несколько версий JDK и JRE; лучше выяснить, какая версия настроена в системном пути к классам для запуска или компиляции программы Java.
JDK также содержит JRE для запуска программы Java.
$JAVA_HOME/bin/java <-- JDK $JAVA_HOME/jre/bin/java <-- JRE
1.1 В Ubuntu или Linux мы можем использовать какой javac
, чтобы узнать, где установлен JDK.
$ which javac /usr/bin/javac $ ls -lsah /usr/bin/javac /usr/bin/javac -> /etc/alternatives/javac $ ls -lsah /etc/alternatives/javac /etc/alternatives/javac -> /usr/lib/jvm/adoptopenjdk-11-hotspot-amd64/bin/javac $ cd /usr/lib/jvm/adoptopenjdk-11-hotspot-amd64/bin/ $ ./javac -version javac 11.0.7
В приведенном выше примере JDK установлен по адресу /usr/lib/jvm/adoptopenjdk-11-hotspot-amd64/
.
1.2 В Windows мы можем использовать где javac
, чтобы узнать, где установлен JDK.
Microsoft Windows [Version 10.0.18362.900] (c) 2019 Microsoft Corporation. All rights reserved. C:\Users\mkyong>which javac 'which' is not recognized as an internal or external command, operable program or batch file. C:\Users\mkyong>where javac C:\opt\jdk-11.0.1\bin\javac.exe
Нужен ли мне JDK или JRE? Для конечных пользователей им необходимо установить JRE для запуска программы Java, а JDK предназначен для разработчиков. В производственной среде команде развертывания необходимо установить JRE только для запуска программы Java. Однако разработчики часто запрашивают установку JDK вместо автономной JRE на рабочем сервере, поскольку JDK содержит JRE, а также дополнительные инструменты для мониторинга и отладки запущенной Java-программы.
Рекомендации
- Википедия – Набор для разработки Java (JDK)
- Википедия – Виртуальная машина Java
- Как установить Java JDK на Ubuntu
Оригинал: “https://mkyong.com/java/how-to-check-current-java-version-installed-in-your-computer/”
-
Метки
computer, jre, terminal, version
Java is a programming language that is platform-independent, popular, simple, secure, and statically typed. Before discussing let’s clear Java language needs a runtime platform so before going ahead let’s clear how java is present on the machine.
Java language comprises three components mainly:
- Java Development Kit
- Java Runtime Environment
- Java Virtual Machine
Runtime Concepts than only we will check whether Java is there on the Platform (Operating System + Architecture)
1. Java Virtual Machine
This is a machine–specific software which is responsible for byte code on that machine and converts it into machine-specific instructions.
JVM is different for Windows JVM is different for Linux JVM is different for Different Platforms
So as a programmer we don’t need to check presence on the machine as it is pre-installed in the machine. It is responsible for running Java code line by line.
2. Java Runtime Environment
It is simply a package that provides an environment to only run our java code on the machine. No development takes place here because of the absence of developmental tools.
3. Java Development Kit
It is also a package that provides an environment to develop and execute where JRE is a part of it along with developmental tools.
- JDK = JRE + Developmental Tools
- JRE = JVM + Library Classes
Now, The first and Foremost step is to check the Java Development Kit in Windows which is also known as JDK. There are lots of versions of Java. Depending upon the operating system methods there are several methods to find the version of Installed JAVA on your Machine:
Let us discuss 3 standard methods in Windows
- User needs to open Command Prompt and enter- ‘java -version’
- Open control panel and lookup for Java
- Directories method- Click the Menu ‘Start’ and typing About.java or readme file
Taking one by one, showcasing in-depth individually
1. Command Prompt
The CMD (Command Interpreter is a command-line Interface. It supports a set of commands and utilities; and has its own programming language for writing batch files. Open CMD and search java -version. First, we have to an environment variable to the installed path location of the java folder. Otherwise, it will show invalid command. It is called ‘Terminal’ in the case of mac operating systems.
java -version // CMD/Terminal command to check java version on the machine
In the case of Windows OS: It is showing java is installed on the machine with version 1.8.0 (See carefully at line number 5)
“1.8.0_144” is the version of the java
In the case of macOS: It is showing java is installed on the machine with version 14.0.1 ( see carefully at line number 2)
Second Method:
- Open Control Panel and there is an option of the java on the interface of the control panel
- Click on the java option and click about a small pop window will appear
In the case of Windows:
In the case of Mac: Click on the Java icon downside. System preferences in mac are the same as the Control panel in Windows.
Third Method:
Search Program and features in the control panel and search JAVA Named option
In the case of Windows: Simply custom search- About Java
In the case of Mac:
Press the command button followed by a spacebar without lifting fingers from the command button.
A popup box will appear for less than a second followed by another pop-up as shown below:
Last Updated :
29 Oct, 2020
Like Article
Save Article
There are different versions of Java is available. Some of the applications generally require different version because of compatibility problems. In this section, we will learn how to check the Java version in Windows using CMD.
A version string contains a version number optionally followed by pre-release and build information. The first number in Java version represents the major version and the second number represents the release. Java provides -version option to find the current Java version.
There are following ways to find the Java version in Windows:
- Using Command Prompt
- Using Java System Class
- Using Control Panel
Note: Before checking the Java version, ensure that Java is installed and the path is properly set.
Using Command Prompt
By using the Command Prompt, we can easily find the Java version. The Java provides -version option to check the Java version. It prints the product version. To find the Java version in CMD, follow the steps given below:
Step 1: Open the Command Prompt by pressing Windows Key + R, type cmd and press enter key or click on the Ok button. It opens the Command Prompt window.
Step 2: Type the following command in the prompt window and press enter key. It shows the Java version.
If the above command shows ‘java’ is not recognized, it means the path is not properly set. To resolve this problem, we must add the Java path to the system environment variable.
Using Java System Class
Another way to find the Java version is to use the System class. It provides the getProperty() method that finds the Java version. The getProperty() method accepts a key as an argument. A key is the name of the system property.
Syntax:
The method returns the String value of the system property, or null if there is no property with that key. It throws NullPointerException if the key is null and IllegalArgumentException if the key is empty.
Let’s find Java version through a program.
FindJavaVersion.java
Output:
We can also find the Java version by using the Control Panel.
Step 1: Open the Control Panel and click on the Java icon. It shows the Java Control Panel.
Step 2: In the Java Control Panel, click on the About button.
When we click on the About button, the About Java dialog box appears that shows the Java version.