Finding java version windows

How to get java version using single command in Windows command prompt?

Why not just call for the java.version property in code and either use that directly or write it to a new blank line in the file? Otherwise I really can’t see what Java (as a programming language) has to do with this.

6 Answers 6

You can run the solution from the question Pangea linked to in a single line:

c:\>for /f "tokens=3" %g in ('java -version 2^>^&1 ^| findstr /i "version"') do @echo %g "1.6.0_24" c:\>for /f "tokens=3" %g in ('java -version 2^>^&1 ^| findstr /i "version"') do ( @set v=%g & @echo %v:~1,8% ) 1.6.0_24

I just checked and it seems my second example only works with Windows7, the following works for me on Windows XP (so it should work on Windows7 as well)

for /f "tokens=3" %g in ('java -version 2^>^&1 ^| findstr /i "version"') do ( @echo %~g )

Hmm, works for me. Do you have the «Command Extensions» enabled? They are by default and that’s what enables the %v:~1,8% syntax

Читайте также:  Всем элементам одно значение java

I have no idea what you just said 😛 what do you mean by «Command Extensions» Also I need to go with whatever comes by default

you can do it from single line from command promt C:>java -version

java -version 2>&1 | awk '/version/ ' | egrep -o '[^\"]*' 
for /f tokens^=2-5^ delims^=.-_^" %j in ('java -fullversion 2^>^&1') do @set "jver=%j%k%l%m" 

This will store the java version into jver variable and as integer And you can use it for comparisons .E.G

if %jver% LSS 16000 echo not supported version 

.You can use more major version by removing %k and %l and %m.This command prompt version.

For .bat use this:

@echo off PATH %PATH%;%JAVA_HOME%\bin\ for /f tokens^=2-5^ delims^=.-_^" %%j in ('java -fullversion 2^>^&1') do set "jver=%%j%%k%%l%%m" 

According to my tests this is the fastest way to get the java version from bat (as it uses only internal commands and not external ones as FIND , FINDSTR and does not use GOTO which also can slow the script). Some JDK vendors does not support -fullversion switch or their implementation is not the same as this one provided by Oracle (better avoid them).

Источник

How to Check Java Version on Mac or Windows

Java runs many of the applications that we use daily. Many applications cannot run on older versions of Java. Hence, it is essential to know which version is installed on your system.

In this tutorial, learn how to check the Java version on your Mac or Windows system.

How to Check if Java is Installed and version on mac or windows

  • A system running macOS or Windows
  • Access to the command-line/terminal window
  • A version of Java installed

Check Java Version on Mac

You can find the version of Java on macOS by:

  • using the GUI (Mac’s System Preferences)
  • prompting for the version in the terminal window

Option 1: Check Java Version on Mac Using the GUI

To check the Java version on Mac without using the terminal by searching for the Java Control Panel in the System Preferences.

1. Click the Apple icon in the menu bar to open the drop-down menu and navigate to System Preferences.

Finding system preferences on Mac

2. A new window opens with various icons and settings. Find and click the Java icon to open the Java Control Panel.

Opening the Java control panel on Mac os

3. Once the Java Control Panel opens, click the About button. A new window with Java version information should appear.

Finding the Java version on macOS from the system preferences

Option 2: Check Java Version on Mac Using the Terminal

If you prefer using the terminal, checking the Java version is a simple one-command process.

1. First, open the terminal. To do so, click the Spotlight Search button in the top-right of the screen.

Mac spotlight search button.

2. Type terminal in the search bar and open it by clicking on the icon in the search results.

Open terminal on Mac.

3. Once in the command line, run the command: java -version . The output should display the Java version installed on your MacOS.

java version 1.8.0_261 installed on macOS

To check the version of the primary Java compiler – javac (pronounced “java-see”) use the command:

Note: If you have a Linux system, refer to How To Check Java Version Installed On Linux.

Check Java Version on Windows

To check the Java version on a Windows computer, you can use:

Option 1: Check Java Version on Windows Using GUI

To find the Java version on your Windows without opening a terminal window, use the Control Panel.

1. Open the Windows menu in the bottom-left corner and type control panel in the search bar.

Searching for the control panel in the Windows start menu.

2. Find the Control Panel in the search results and click the icon to open it.

Opening the control panel on Windows

3. Move to the Programs directory.

screenshot of the Open programs directory in Windows

4. Find and click the Java icon to open the Java Control Panel.

example of opening the Java Control Panel

5. Once the control panel opens, click the About button.

Viewing information about the Java control panel

6. The About Java window should appear and display the Java version on your computer.

example output of java version 8 update 261 installed on windows

Option 2: Check Java Version on Windows Using Command Line

Another option to find the Java version on Windows is through the command line.

1. Open the Windows Start menu in the bottom-left corner and type cmd in the search bar.

Search for command prompt on Windows

2. Then, open the Command Prompt once it appears in the search results.

Open command prompt on Windows

3. A new window with the command prompt should appear. In it, type the command java -version and hit Enter. The output should display the Java version installed on your Windows system.

java version 1.8.0_261 installed on windows

You can also check the version of the Java’s primary compiler, javac, with the command:

This article showed you how to check the version of Java installed on a macOS or Windows system.

Источник

How to Check Java Version

In today’s blog, we will be showing you how to check the Java version on Windows and macOS operating systems.

How to Check Java Version

List of content you will read in this article:

Among all the programming languages, Java is considered to be the most commonly used language that has been adopted worldwide. There are numerous reasons why Java has gained popularity over other alternatives. There is no doubt that Java has been famous among all Fortune 500 companies and is widely recommended by developers. Its user-friendly and flexible nature makes it a go-to programming language for web developers and programmers.

The main reasons behind Java being popular is its fast speed, high-end security, and reliability. Along with such benefits, Java also offers private transmission, automatic memory management, and secure crucial information.

About Java

Introduced in the 1990s by James Gosling, Java is an object-oriented, robust, and secure programming language. The team started this Java project to develop a language suitable, especially for digital devices like set-top boxes, television, etc. At first, C++ was to be used in the Java project but was not considered for some reasons. Later, Gosling expanded C++ and led to another stage of a project Green, which was later renamed the ‘Greentalk’ project by Gosling and his team members. These project files had the file extension as .gt, which is later recognized as ‘OAK.’

The name ‘OAK’ was given to the project after an oak tree that was located outside Gosling’s office. But later on, the term ‘OAK’ was changed to Java. After various talks and brainstorming sessions, Gosling and his team come to multiple names- JAVA, DNA, SILK, BURY, etc. Still, they decided on JAVA after many discussions due to its uniqueness. This name (Java) comes up from a type of espresso bean. Gosling and his team members had come up with this name while having a cup of coffee near their office.

The main principles on which Java was built are- robust, portable, platform-independent, multi-thread, etc. In 1995, Java was recognized as one of the ten best products in Time magazine. Today, Java has been used in various fields like internet programming, mobile devices, games, etc. later, multiple versions of Java have been introduced over the years with new added features and functionalities.

Versions of Java

Over time, Java has introduced various versions with different and advanced features than the earlier version. Every version has fulfilled the drawback of their previous versions. Some of the versions are still supported, and some of them are not. Below is the list of all the Java versions introduced to date.

Support Until

Источник

How to know the jdk version on my machine?

First uninstall all the versions of Java, install Jdk 8. Open new command prompt and type java -version.

If your JDK is on your path you should be able to tell by just running ‘javac -version’. From the error you described it sounds like you’re on Windows, so if the first command fails try executing (with the quotes) the following: «%JAVA_HOME%\bin\javac -version»

@AlexBroadwin your method worked for me. But i’ve installed 8th version and in cmd «1.8.0_221» is coming. What does that mean?

4 Answers 4

you might need to add path in environment variables which you can find in Control Panel open the Jdk where you installed and add until /bin in the path in environment variables.

Add until /bin in path variable in System Variables which is residing in Environment Variables.

Then do java -version which might show up.

If still problem persists, try restarting your pc and see.

Your method worked for me. But i’ve installed jdk version 8 and in cmd java version «1.8.0_221» is coming. What does that mean?

you are good, you have installed Java 8 and the _221 is just the update release(They keep on adding some features or there will be minor updates), for more info you can refer by clicking here oracle.com/technetwork/java/javase/…

-version is useless: C:\Windows\system32>java -version java version «1.8.0_281» Java(TM) SE Runtime Environment (build 1.8.0_281-b09) Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)

You need to update your Windows path to include your %JAVA_HOME%\bin directory. %JAVA_HOME% is the directory that you installed Java into and is also an environment variable that you need to configure for command line execution of your applications. You can edit both of these in the Windows control panel and you should restart.

When you run java -version you will see the internal version number. This is explained here: https://en.wikipedia.org/wiki/Java_version_history.

Basically, you can ignore the 1. when reading version number. The _xxx is a reference to the most recent patch or build release.

java version vs jdk versions could be different ? Seems useless or confusing at best ! JDK, JSE, it’s all a bit bloody mess

On Windows 10, this required mapping the environment variable for JAVA_HOME to the JDK installation directory. Use these steps:

enter image description here

  1. Run the installer for the JDK. (available for windows here: https://www.oracle.com/java/technologies/downloads/#jdk17-windows)
  2. windows key -> Environment Variables , select the only result
  3. In the System Properties window that opened, select Environment Variables
  4. Select new button under the User variables section
  5. Variable name: JAVA_HOME , Variable Value:
  6. ok all open menus
  7. Close any open cmd prompt windows
  8. open a new cmd window and type echo %JAVA_HOME% It should print the installation path for the JDK.

To get your jdk location in Windows, run this at a command prompt:

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.

Источник

Оцените статью