Command line for java version

How to find the version of Java using command line?

Solution 2: you can do it from single line from command promt C:>java -version Solution 3: You can try: Solution 4: This will store the java version into variable and as integer And you can use it for comparisons .E.G .You can use more major version by removing %k and %l and %m.This command prompt version. Path: C:\Program Files\Common Files\Microsoft Shared\Windows Live; %SystemRoot%\system32; %SystemRoot%; %SystemRoot%\System32\Wbem; %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\; C:\Program Files\TortoiseSVN\bin; C:\Program Files\Windows Live\Shared; C:\eclipse\plugins\com.google.appengine.eclipse.sdkbundle_1.6.5\appengine-java-sdk-1.6.5\bin; C:\Program Files\Java\jdk1.7.0_07\bin;C:\Program Files\QuickTime\QTSystem\; %ANT_HOME%\bin Just want to let you guys know that it somehow automatically became a jre.

How to find the version of Java using command line?

You can find the version of the Java software currently installed in your system using Programs and using Command prompt .

Using Command prompt

The — version command of the java command prompt gives you the current Version of the Java software installed in your system.

Therefore, open command prompt and type the command java -version to get the version of Java installed in your system.

Java Command Line

Using the Java program

The System class of java.lang package provides a method named getProperty() this method accepts one of the following string parameters an returns the respective property.

Читайте также:  Get text from pdf java

To get the version of the java installed in the system, invoke the getProperty() method by passing the value «os.name» to it, as shown in the following sample code.

Example

Output

Current Java version is: 1.8.0_101

Check Java Version in Linux, To check the version using this method, execute the following command in your Linux terminal. update-alternatives —list java Output: /usr/lib/jvm/java-11-openjdk-amd64/bin/java Note that the output can vary depending on your machine and Java version. Use the whereis Command to Check the Java Version in Linux

Different Java version showing on command line

I have recently checked on my Java version . I ran the command java -version and I found out that I was using java version 1.7.0_09 . But when I tried to check on C:\Program Files\Java\ directory, I don’t seem to find the same version. I only see the following:

My programs still run, but I’m just trying to compile everything manually, and understand how Java is being treated by the OS.

Another thing that is weird is, I tried to check on environment variable settings , and it does not say anything about jdk1.7.0_09 .

  • C:\Program Files\Common Files\Microsoft Shared\Windows Live;
  • %SystemRoot%\system32;
  • %SystemRoot%;
  • %SystemRoot%\System32\Wbem;
  • %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;
  • C:\Program Files\TortoiseSVN\bin;
  • C:\Program Files\Windows Live\Shared;
  • C:\eclipse\plugins\com.google.appengine.eclipse.sdkbundle_1.6.5\ appengine-java-sdk -1.6.5\bin;
  • C:\Program Files\Java\jdk1.7.0_07\bin;C:\Program Files\QuickTime\QTSystem\;
  • %ANT_HOME%\bin

Just want to let you guys know that it somehow automatically became a jre.

The complete directory is C:\Users\User02\AppData\LocalLow\Sun\Java\jre1.7.0_09 and it’s just got the file named lzma.dll .

But, I have another directory that says C:\Users\User02\AppData\LocalLow\Sun\Java\jdk1.7.0_07 . The files inside it are:

  • jdk1.7.0_07.msi
  • sj170070.cab
  • ss170070.cab
  • st170070.cab
  • and sz170070.cab

It’s possible to have many JRE side-by-side on a computer.

If the JRE is properly installed on Windows, informations about each version are stored in the registry. The installation process installs a special java.exe in the system PATH ( %SYSTEMROOT%\System32 ). So you don’t need to alter you PATH because this special java.exe will find the current JRE. From a command line, type java -version to display the current jre version installed.

With release 1.6, it’s now possible to select a different JRE installation than the last one without any registry modification.

The JRE installation are listed in the registry in the key

HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment

Take this simple test class

On a system, with 1.6 and 1.5 installed. If you type

It’s probably the 1.6 JRE that will be used since it’s the last installed.

To force the 1.5 JRE instead, use this command line.

> java -version:"1.5" ShowVersion 

If the bytecode is incompatible with the given JRE then .. it won’t work, of course.

You can always give the complete path to use a specific installation. Launching the JVM this way does not use the registry setting at all.

>"C:\Program Files\Java\j2re1.4.1_02\bin\java" -version java version "1.4.1_02" 

source : Select a particular JRE from the command line

Adding the following will resolve your issue:

set JAVA_HOME="your jdk path" set PATH=%JAVA_HOME%\bin;%PATH%. 

Additionally if it does not work that means you have set the PATH for multiple java version s, include only the latest one and remove all from PATH variables.

That AppData path in your comment isn’t on your path (supposedly, anyway), so that’s probably not what it’s using. Unfortunately, there isn’t a which command on Windows either.

If you edit your path and move the C:\Program Files\Java\bin directory to the very beginning of the list and it still prints 1.7.0_09 , then somehow you have JDK7u9 in your JDK7u7 folder. If not, browse to all the other directories on your path and open them 1-by-1 until you find the appropriate java file. Fortunately for you, your path is much shorter than mine.

It may also look for java.bat and other non- exe extensions, so keep an eye out for this while you’re searching your path. Try running:

That way you know you’re looking for an exe file.

One last thing you can try:

> "C:\Program Files\Java\jdk1.7.0_07\bin\java" -version 

If this returns 1.7.0_09 , then something happened that updated your JDK in-place, which isn’t supposed to happen, AFAIK (but I could be wrong).

In answer to the «actual» question:

Another thing that is weird is, I tried to check on environment variable settings, and it does not say anything about jdk1.7.0_09.

What happened here is that you installed jdk1.7.0_07 and then you auto-upgraded it. When that happens , it still uses the old folder name that you originally installed to.

After I install Java , I usually make a copy of the JDK directory and name it with the version number. Then, I can directly call a certain java like so:

@echo off :: testjava.bat set JAVA_HOME=C:\JDK1.**** set PATH=%JAVA_HOME%\bin;%PATH%;. java -version pause 

So, my recommendation is to set your JAVA_HOME system variable and PATH variable like I show above. This would override everything on your system so that your JDK of your choice is the default over the JRE.

Changing the active java version using cmd, Then inspect and adjust your PATH variables accordingly, and perhaps some other Java-related environment variables, if required. You can also plain and simple run your desired java like /opt/local/java-1.6/bin/java -jar MyClass.jar or similar. – amn. Oct 5, 2017 at 13:37. If you are building from …

JAVA_HOME and java -version

I’m using a Windows .bat script and I set JAVA_HOME as C:/Program Files/Java/jdk1.6.0_32 when I do a java -version , it still shows the 1.3

How can I fix this? What am I doing wrong?

For me the issue was in my PATH variable, C:\ProgramData\Oracle\Java\javapath; was added by java windows install before my %JAVA_HOME%\bin; . So I’d echo %JAVA_HOME% pointing to a JDK7 and java -version showing jdk8.

I’d to put %JAVA_HOME%\bin; before C:\ProgramData\Oracle\Java\javapath; so that java -version displays jdk7.

Try %JAVA_HOME%\bin\java -version

If you modify JAVA_HOME , it’s usually better to invoke java with an absolute path (using JAVA_HOME ) because the new binary is probably not in the path (and then Windows will load the wrong binary).

Make sure that the PATH environment variable is pointing to %JAVA_HOME%\bin .

Be sure not to mix the system variable path and the user variable system path. I feel OK in calling java without the absolute path (when I know how JAVA_HOME and PATH are configured).

Different Ways To Check Java Version 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 Promp t The CMD (Command Interpreter is a command …

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

I need to fetch java version 1.6.0_26 from the below java -version output

java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03) Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing) 

Please help me getting 1.6.0_26

Note: I don’t need power shell or any external programs

I came up with java -version 2>&1 | findstr /i «version» which give me below output

now even a java way of pattern matching or regex will work for me 🙂

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 )

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 your java version cmd Code Example, java -version #for jre version javac -version # for java compiler version

Источник

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