Как узнать какая java установлена 32 или 64
Перейти к содержимому

Как узнать какая java установлена 32 или 64

  • автор:

Как узнать битность java

Для того, чтобы узнать битность Java , можно выполнить следующие действия:

  1. Запустите командную строку.
  2. Введите команду java -version
  3. Найдите строку, начинающуюся с «java version»
  4. Если в этой строке есть фраза «64-bit», то установлена 64-битная версия Java , иначе — 32-битная версия.

Например, вот пример вывода, который указывает на установку 64-битной версии Java :

"1.8.0_221" Java(TM) SE Runtime Environment (build 1.8.0_221-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode) 

How to find if java.exe is 32-bit or 64-bit?

I have a laptop with Windows 7 Professional 64-bit operating system. It has a C:\ProgramData\Oracle\Java\javapath folder which contains java.exe . How can I know if this JVM is 32-bit or 64-bit? I right-click on it and open Properties window and under Detail tab the File version is 8.0.1210.13 . But there is no information if it is 32-bit or 64-bit.

asked Apr 17, 2017 at 15:48
1,661 5 5 gold badges 31 31 silver badges 58 58 bronze badges
Not exact duplicate but take a look at: stackoverflow.com/a/2062263
Apr 17, 2017 at 16:00

Make sure that you know what is always in your path because «java -cp . » will use that one. Not the hardcoded one

Apr 17, 2017 at 16:08

3 Answers 3

You can run C:\ProgramData\Oracle\Java\javapath\java.exe -version . Among the details it prints out, you should see whether it’s a 32 or 64 bit version.

A 32 bit version will return something about a «Client VM» or «Server VM», and a 64 bit version will state so explicitly.

E.g., the output of my machine (admittedly, a Fedora 25, but the principle should stand):

openjdk version "1.8.0_121" OpenJDK Runtime Environment (build 1.8.0_121-b14) OpenJDK 64-Bit Server VM (build 25.121-b14, mixed mode) 

308k 103 103 gold badges 860 860 silver badges 1170 1170 bronze badges
answered Apr 17, 2017 at 15:50
298k 52 52 gold badges 308 308 silver badges 352 352 bronze badges
this depends on whichever JVM is on path first;
Apr 17, 2017 at 15:53

@srh: Obviously, if you want a specific java.exe , do C:\ProgramData\Oracle\Java\javapath\bin\java -version instead.

Apr 17, 2017 at 15:53

@srh, naturally, you should explicitly run it on the executable you want to evaluate, not count on the PATH. I’ll edit my answer to make it clearer, though.

Apr 17, 2017 at 15:54

I get this result java version «1.8.0_121» Java(TM) SE Runtime Environment (build 1.8.0_121-b13) Java HotSpot(TM) Client VM (build 25.121-b13, mixed mode, sharing) . So as per your answer it is 32-bit?

Apr 17, 2017 at 16:01
@srh yes. That’s a 32 bit Java.
Apr 17, 2017 at 16:02

You could check os.arch

System.out.println(System.getProperty("os.arch")); 

32 bit architecture is typically represented by x86_32 or just x86 , 64 bit architecture by x86_64

answered Apr 17, 2017 at 16:00
158k 15 15 gold badges 217 217 silver badges 276 276 bronze badges

That determines the architecture of the host OS. It is a lucky coincidence, that this returns the desired value for all combinations of host OS bitnesses and JVM bitnesses on Windows. Specifically, if a 32-bit JVM is running in the WoW64 emulator the OS will lie to it about its architecture, and report a 32-bit architecture. This is really more of a code-by-coincidence strategy than a genuine solution.

Apr 17, 2017 at 21:07

@IInspectable at least on Windows, os.arch is not the host OS. It is the process arch. Try it, or read stackoverflow.com/a/37028080/280534

Jul 11, 2018 at 16:08

@KevinSmyth: As per documentation, the «os.arch» property returns the «Operating system architecture». Your link talks about a JVM implementation, that simply takes shortcuts to implement, what I explained in my previous comment. It reports the bitness of the calling process, because that’s exactly what the OS would report, even if a lie. This solution fails in case a competing JVM implementation chooses to report the true OS architecture.

Jul 12, 2018 at 11:16

To reliably determine the bitness of an executable image you’ll need tool support. This can be as simple as a hex editor, to inspect the contents of the PE Image. You can determine the machine type of the binary by following these steps:

  1. Move to location 0x3c, and note the value of the 4 bytes there (little endian order). Those are the offset from the beginning of the file to the PE Signature.
  2. Move to the location noted in step 1, and verify, that the 4 bytes have the values 0x50 0x45 0x00 0x00 ( PE\0\0 ). That’s the signature of a PE image. If the values are different, this is not an executable image.
  3. Move past the signature and note the next 2 bytes (little endian order). This value denotes the machine type of the binary image.
  4. Compare the value against the supported Machine Types:
    • 0x014c corresponds to x86 (32 bits).
    • 0x8664 corresponds to x64 (64 bits).

While simple and reliable, it takes a certain amount of care. There are easier ways, using other tools. In case you have Visual Studio installed, you can use DUMPBIN to have it report the machine type by executing the following command at the command prompt:

dumpbin.exe /HEADERS | findstr machine 

This will produce the following output (x86 and x64, respectively):

 14C machine (x86) 
 8664 machine (x64) 

If you don’t have Visual Studio or don’t want to install it, you could use Process Explorer to determine the bitness of a running process. To do so, right-click the respective process in the Process treeview, and select Properties. . On the Image tab you’ll see the process’ bitness spelled out.

Определить битность Java

Определить битность Java
Как определить 32 или 64 битная Java установлена? Добавлено через 22 часа 46 минут Никто что-ли.

Как узнать битность Java средствами С#?
Доброго времени суток.Как можно узнать битность Java(установленной на ПК) средствами с#?

Определить битность системы
Надо в vbs скрипте определить битность системы и в зависимости от нее выполнить разные приложения.

Битность Windows
Можно ли заставить C# проверить битность системы? х86(32bit) или х64 (64bit).

How can I tell if I’m running in 64-bit JVM or 32-bit JVM (from within a program)?

How can I tell if the JVM in which my application runs is 32 bit or 64-bit? Specifically, what functions or properties I can used to detect this within the program?

7,440 4 4 gold badges 54 54 silver badges 66 66 bronze badges
asked Jan 14, 2010 at 3:38
19.9k 10 10 gold badges 45 45 silver badges 57 57 bronze badges

Just out of curiosity, why would you need to know the natural size of the system? Details such as this are abstracted away in Java, so you shouldn’t (in theory, at least) have to know them.

Jan 14, 2010 at 4:29

It lets me roughly estimate the memory requirements for objects due to pointers. Curiosity too — seemed like there should be a way, but I’d never heard of it.

Jan 14, 2010 at 18:33

This «detail» is not abstracted away when interacting with the Java Native Interface. 32-bit DLLs can’t be loaded with a 64-bit JVM (and vice versa). So this is quite essential information for anyone using JNI. It’s a pity that there seems to be no portable way to obtain this info. One way is to first try loading a 32-bit version of the DLL, and if it fails, try the 64-bit version, etc. Ugly!

Apr 30, 2010 at 7:17

Another situation where discerning between 32 or 64 bit JVMs is important is for mapped files. On 32 bit systems only 2GB can be mapped, so it’s important to map and unmap file segments accordingly so that this limit is not exceeded, while on 64 bit jvms the limit is much, much, much higher.

Sep 9, 2012 at 21:07

It’s really nice to be able to choose the numerical algorithm that will be fastest on the machine in question.

Apr 22, 2014 at 18:09

13 Answers 13

For certain versions of Java, you can check the bitness of the JVM from the command line with the flags -d32 and -d64 .

$ java -help . -d32 use a 32-bit data model if available -d64 use a 64-bit data model if available 

To check for a 64-bit JVM, run:

$ java -d64 -version 

If it’s not a 64-bit JVM, you’ll get this:

Error: This Java instance does not support a 64-bit JVM. Please install the desired version. 

Similarly, to check for a 32-bit JVM, run:

$ java -d32 -version 

If it’s not a 32-bit JVM, you’ll get this:

Error: This Java instance does not support a 32-bit JVM. Please install the desired version. 

These flags were added in Java 7, deprecated in Java 9, removed in Java 10, and no longer available on modern versions of Java.

6,410 3 3 gold badges 32 32 silver badges 48 48 bronze badges
answered Jan 14, 2010 at 5:00
12k 3 3 gold badges 27 27 silver badges 26 26 bronze badges

Exactly what I was looking for. And you can run java -d32 -version to verify you are not running 32-bit. Both wish work on Win7 .

Feb 2, 2012 at 20:34

I am on Windows 7, and I get ‘unrecognized option’ error from java -d32 -version and also from java -d64 -version .

Apr 20, 2012 at 20:29

Do not use «-D64», for that does something completely different. It defines a system property called «64». This is definitely not what is wanted here.

Jul 30, 2014 at 12:00
The -d32 or -d64 flags will only work for a Java 7 or greater.
Aug 8, 2014 at 10:41

This argument was removed in Java 9, see JDK-8168010. Additionally it might not satisfy «from within a program» reliably, given that Solaris supported both pre JDK8 and therefore you could likely currently be running with a 32 bit data model, but java -d64 -version returned with exit code 0.

Sep 12, 2018 at 7:50

You retrieve the system property that marks the bitness of this JVM with:

System.getProperty("sun.arch.data.model"); 

Possible results are:

  • «32» – 32-bit JVM
  • «64» – 64-bit JVM
  • «unknown» – Unknown JVM

As described in the HotSpot FAQ:

When writing Java code, how do I distinguish between 32 and 64-bit operation?

There’s no public API that allows you to distinguish between 32 and 64-bit operation. Think of 64-bit as just another platform in the write once, run anywhere tradition. However, if you’d like to write code which is platform specific (shame on you), the system property sun.arch.data.model has the value «32», «64», or «unknown».

An example where this could be necessary is if your Java code depends on native libraries, and you need to determine whether to load the 32- or 64-bit version of the libraries on startup.

1 1 1 silver badge
answered Jan 14, 2010 at 3:44
447k 82 82 gold badges 493 493 silver badges 529 529 bronze badges

I wouldn’t expect to find sun.* system properties with an IBM JVM. In other words, it’s not portable.

Jan 14, 2010 at 23:19
How can you tell from the command line? If you are running 32-bit or 64-bit? Just curious.
Feb 2, 2012 at 20:33

Why is the accepted answer Sun-dependent? «os.arch» will accomplish the same thing without having to use proprietary sun packages.

May 24, 2012 at 10:38

@b1naryatr0phy, does os.arch report on the Operating System, or the JVM? I often run 32-bit JVM on my 64-bit workstation, for development purposes.

Aug 8, 2012 at 17:19
This property is supported on IBM JVMs, but not on GCJ. See stackoverflow.com/questions/807263/…
Nov 9, 2012 at 13:13

Just type java -version in your console.

If a 64 bit version is running, you’ll get a message like:

java version "1.6.0_18" Java(TM) SE Runtime Environment (build 1.6.0_18-b07) Java HotSpot(TM) 64-Bit Server VM (build 16.0-b13, mixed mode) 

A 32 bit version will show something similar to:

java version "1.6.0_41" Java(TM) SE Runtime Environment (build 1.6.0_41-b02) Java HotSpot(TM) Client VM (build 20.14-b01, mixed mode, sharing) 

Note Client instead of 64-Bit Server in the third line. The Client/Server part is irrelevant, it’s the absence of the 64-Bit that matters.

If multiple Java versions are installed on your system, navigate to the /bin folder of the Java version you want to check, and type java -version there.

24.4k 8 8 gold badges 57 57 silver badges 73 73 bronze badges
answered Jun 3, 2011 at 20:58
Sedat Kilinc Sedat Kilinc
2,863 1 1 gold badge 24 24 silver badges 20 20 bronze badges
but in hp nonstop oss env I’m not getting 64bit or 32 bit
Jul 23, 2015 at 13:25
OP specifically says within the program.
Sep 21, 2015 at 12:20

I installed 32-bit JVM and retried it again, looks like the following does tell you JVM bitness, not OS arch:

System.getProperty("os.arch"); # # on a 64-bit Linux box: # "x86" when using 32-bit JVM # "amd64" when using 64-bit JVM 

This was tested against both SUN and IBM JVM (32 and 64-bit). Clearly, the system property is not just the operating system arch.

7,440 4 4 gold badges 54 54 silver badges 66 66 bronze badges
answered Jan 14, 2010 at 3:47
3,425 1 1 gold badge 30 30 silver badges 30 30 bronze badges

Yeah. It gives x86, etc. Not quite the same thing, since I’m not sure if it gives «x64» for x86-64 running in 64-bit rather than 32-bit.

Jan 14, 2010 at 4:11
@codaddict, looks like it is JVM bitness indeed.
Jan 14, 2010 at 23:14

@codaddict That is completely false (and I have no idea why six ppl have voted that comment up.) «os.arch» is designed to return the JVM version. Test it out for yourself and god help you if you’re actually relying on this for OS detection.

May 24, 2012 at 10:36

os.arch has many possible values, it’s difficult to tell if it’s 32 or 64 bits. See lopica.sourceforge.net/os.html

Nov 9, 2012 at 13:15

This is a string intended for human eyes and without a strict definition of valid values, relying on this is not a good idea — write code that checks actual functionality instead.

Jul 9, 2013 at 22:34

On a running process you may use (at least with some recent Sun JDK5/6 versions):

$ /opt/java1.5/bin/jinfo -sysprops 14680 | grep sun.arch.data.model Attaching to process ID 14680, please wait. Debugger attached successfully. Server compiler detected. JVM version is 1.5.0_16-b02 sun.arch.data.model = 32 

where 14680 is PID of jvm running the application. «os.arch» works too.

Also other scenarios are supported:

jinfo [ option ] pid jinfo [ option ] executable core jinfo [ option ] [server-id@]remote-hostname-or-IP 

However consider also this note:

«NOTE — This utility is unsupported and may or may not be available in future versions of the JDK. In Windows Systems where dbgent.dll is not present, ‘Debugging Tools for Windows’ needs to be installed to have these tools working. Also the PATH environment variable should contain the location of jvm.dll used by the target process or the location from which the Crash Dump file was produced.»

answered Feb 16, 2012 at 19:04
1,707 2 2 gold badges 13 13 silver badges 21 21 bronze badges

On Linux, you can get ELF header information by using either of the following two commands:

file /bin/java 

o/p: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.4.0, dynamically linked (uses shared libs), for GNU/Linux 2.4.0, not stripped

readelf -h /bin/java | grep 'Class' 

o/p: Class: ELF64

answered Jun 7, 2012 at 8:50
313 2 2 silver badges 12 12 bronze badges

If you are using JNA, you can check whether com.sun.jna.Native.POINTER_SIZE == 4 (32 bit) or com.sun.jna.Native.POINTER_SIZE == 8 (64 bit).

7,970 7 7 gold badges 61 61 silver badges 66 66 bronze badges
answered Apr 10, 2015 at 16:49
Anthony Hayward Anthony Hayward
2,184 21 21 silver badges 18 18 bronze badges

This is clever but accessing the pointer size is significantly slower than the other solutions here (it needs some time to initialize).

Aug 7, 2018 at 20:44

If you’re using JNA, you can do this Platform.is64Bit() .

answered Jan 8, 2019 at 3:43
51 1 1 silver badge 1 1 bronze badge

 public static final boolean is64Bit() < String model = System.getProperty("sun.arch.data.model", System.getProperty("com.ibm.vm.bitmode")); if (model != null) < return "64".equals(model); >if ("x86-64".equals(ARCH) || "ia64".equals(ARCH) || "ppc64".equals(ARCH) || "ppc64le".equals(ARCH) || "sparcv9".equals(ARCH) || "mips64".equals(ARCH) || "mips64el".equals(ARCH) || "amd64".equals(ARCH) || "aarch64".equals(ARCH)) < return true; >return Native.POINTER_SIZE == 8; > ARCH = getCanonicalArchitecture(System.getProperty("os.arch"), osType); static String getCanonicalArchitecture(String arch, int platform) < arch = arch.toLowerCase().trim(); if ("powerpc".equals(arch)) < arch = "ppc"; >else if ("powerpc64".equals(arch)) < arch = "ppc64"; >else if ("i386".equals(arch) || "i686".equals(arch)) < arch = "x86"; >else if ("x86_64".equals(arch) || "amd64".equals(arch)) < arch = "x86-64"; >// Work around OpenJDK mis-reporting os.arch // https://bugs.openjdk.java.net/browse/JDK-8073139 if ("ppc64".equals(arch) && "little".equals(System.getProperty("sun.cpu.endian"))) < arch = "ppc64le"; >// Map arm to armel if the binary is running as softfloat build if("arm".equals(arch) && platform == Platform.LINUX && isSoftFloat()) < arch = "armel"; >return arch; > static < String osName = System.getProperty("os.name"); if (osName.startsWith("Linux")) < if ("dalvik".equals(System.getProperty("java.vm.name").toLowerCase())) < osType = ANDROID; // Native libraries on android must be bundled with the APK System.setProperty("jna.nounpack", "true"); >else < osType = LINUX; >> else if (osName.startsWith("AIX")) < osType = AIX; >else if (osName.startsWith("Mac") || osName.startsWith("Darwin")) < osType = MAC; >else if (osName.startsWith("Windows CE")) < osType = WINDOWSCE; >else if (osName.startsWith("Windows")) < osType = WINDOWS; >else if (osName.startsWith("Solaris") || osName.startsWith("SunOS")) < osType = SOLARIS; >else if (osName.startsWith("FreeBSD")) < osType = FREEBSD; >else if (osName.startsWith("OpenBSD")) < osType = OPENBSD; >else if (osName.equalsIgnoreCase("gnu")) < osType = GNU; >else if (osName.equalsIgnoreCase("gnu/kfreebsd")) < osType = KFREEBSD; >else if (osName.equalsIgnoreCase("netbsd")) < osType = NETBSD; >else < osType = UNSPECIFIED; >> 

answered Sep 10, 2020 at 13:36
Fabian Knapp Fabian Knapp
1,342 13 13 silver badges 27 27 bronze badges

You can use a JNI library. This will always work and is independent of the running JVM brand.

package org.mytest; public class NativeBinding < public static native int getRegisterWidth(); // returns 32 or 64 >

And this is the C code:

#include // will return register width (32 or 64) extern "C" JNIEXPORT jint JNICALL Java_org_mytest_NativeBinding_getRegisterWidth(JNIEnv*, jclass)

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *