Test if java is 64 bit

How do I detect which kind of JRE is installed — 32bit vs. 64bit

During installation with an NSIS installer, I need to check which JRE (32bit vs 64bit) is installed on a system. I already know that I can check a system property » sun.arch.data.model «, but this is Sun-specific. I’m wondering if there is a standard solution for this.

9 Answers 9

The JVM architecture in use can be retrieved using the «os.arch» property:

The «os» part seems to be a bit of a misnomer, or perhaps the original designers did not expect JVMs to be running on architectures they weren’t written for. Return values seem to be inconsistent.

The NetBeans Installer team are tackling the issue of JVM vs OS architecture. Quote:

  • for Windows it can be done using WindowsRegistry.IsWow64Process()
  • for Linux — by checking ‘uname -m/-p’ == x86_64
  • for Solaris it can be done using e.g. ‘isainfo -b’
  • for Mac OSX it can’t be done using uname arguments, probably it can be solved by creating of 64-bit binary and executing on the platform. (unfortunately, this does not work:( I’ve created binary only with x86_64 and ppc64 arch and it was successfully executed on Tiger..)
  • for Generic Unix support — it is not clear as well. likely checking for the same ‘uname -m/-p’ / ‘getconf LONG_BIT’ and comparing it with some possible 64-bit values (x86_64, x64, amd64, ia64).

Sample properties from different JVMs all running on 64bit Ubuntu 8.0.4:

java.vendor=IBM Corporation java.vendor.url=http://www.ibm.com/ java.version=1.5.0 java.vm.info=J2RE 1.5.0 IBM J9 2.3 Linux x86-32 j9vmxi3223-20061001 (JIT enabled) J9VM - 20060915_08260_lHdSMR JIT - 20060908_1811_r8 GC - 20060906_AA java.vm.name=IBM J9 VM java.vm.specification.name=Java Virtual Machine Specification java.vm.specification.vendor=Sun Microsystems Inc. java.vm.specification.version=1.0 java.vm.vendor=IBM Corporation java.vm.version=2.3 os.arch=x86 os.name=Linux os.version=2.6.24-23-generic sun.arch.data.model=32 
java.vendor=Sun Microsystems Inc. java.vendor.url=http://java.sun.com/ java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi java.version=1.6.0_05 java.vm.info=mixed mode java.vm.name=Java HotSpot(TM) 64-Bit Server VM java.vm.specification.name=Java Virtual Machine Specification java.vm.specification.vendor=Sun Microsystems Inc. java.vm.specification.version=1.0 java.vm.vendor=Sun Microsystems Inc. java.vm.version=10.0-b19 os.arch=amd64 os.name=Linux os.version=2.6.24-23-generic sun.arch.data.model=64 
java.vendor=Free Software Foundation, Inc. java.vendor.url=http://gcc.gnu.org/java/ java.version=1.5.0 java.vm.info=GNU libgcj 4.2.4 (Ubuntu 4.2.4-1ubuntu3) java.vm.name=GNU libgcj java.vm.specification.name=Java(tm) Virtual Machine Specification java.vm.specification.vendor=Sun Microsystems Inc. java.vm.specification.version=1.0 java.vm.vendor=Free Software Foundation, Inc. java.vm.version=4.2.4 (Ubuntu 4.2.4-1ubuntu3) os.arch=x86_64 os.name=Linux os.version=2.6.24-23-generic 

(The GNU version does not report the «sun.arch.data.model» property; presumably other JVMs don’t either.)

Источник

Проверьте, работает ли программа Java в 64-битной или 32-битной JVM

Хотя Java не зависит от платформы, бывают случаи, когда нам приходится использовать нативные библиотеки. В этих случаях нам может потребоваться определить базовую платформу и загрузить соответствующие собственные библиотеки при запуске.

Читайте также:  React this state typescript

В этом руководстве мы изучим различные способы проверки того, работает ли программа Java на 64-разрядной или 32-разрядной JVM .

Сначала мы покажем, как этого добиться с помощью класса System .

Затем мы увидим, как использовать API Java Native Access (JNA) для проверки разрядности JVM. JNA — это библиотека, разработанная сообществом, которая обеспечивает любой собственный доступ.

2. Использование системного свойства sun.arch.data.model ​

Класс System в Java обеспечивает доступ к внешним свойствам и переменным среды. Он поддерживает объект Properties , описывающий конфигурацию текущей рабочей среды.

Мы можем использовать системное свойство « sun.arch.data.model » для определения разрядности JVM:

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

Он содержит «32» или «64» для обозначения 32-битной или 64-битной JVM соответственно. Хотя этот подход прост в использовании, он возвращает «неизвестно», если свойство отсутствует. Следовательно, он будет работать только с версиями Oracle Java.

 public class JVMBitVersion    public String getUsingSystemClass()    return System.getProperty("sun.arch.data.model") + "-bit";   >    //. other methods   > 

Давайте проверим этот подход с помощью модульного теста:

 @Test   public void whenUsingSystemClass_thenOutputIsAsExpected()    if ("64".equals(System.getProperty("sun.arch.data.model")))    assertEquals("64-bit", jvmVersion.getUsingSystemClass());   > else if ("32".equals(System.getProperty("sun.arch.data.model")))    assertEquals("32-bit", jvmVersion.getUsingSystemClass());   >   > 

3. Использование JNA API​

JNA ( Java Native Access ) поддерживает различные платформы, такие как macOS, Microsoft Windows, Solaris, GNU и Linux.

Он использует собственные функции для загрузки библиотеки по имени и получения указателя на функцию в этой библиотеке.

3.1. Родной класс​

Мы можем использовать POINTER_SIZE из класса Native . Эта константа указывает размер (в байтах) собственного указателя на текущей платформе.

Значение 4 указывает на 32-битный собственный указатель, а значение 8 указывает на 64-битный собственный указатель:

 if (com.sun.jna.Native.POINTER_SIZE == 4)    // 32-bit   > else if (com.sun.jna.Native.POINTER_SIZE == 8)    // 64-bit   > 

3.2. Класс платформы ​

В качестве альтернативы мы можем использовать класс Platform , который предоставляет упрощенную информацию о платформе.

Он содержит метод is64Bit() , который определяет, является ли JVM 64-разрядной или нет .

Давайте посмотрим, как он определяет разрядность:

 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 получена из свойства « os.arch » через класс System . Он используется для получения архитектуры операционной системы:

 ARCH = getCanonicalArchitecture(System.getProperty("os.arch"), osType); 

Этот подход работает для разных операционных систем, а также для разных поставщиков JDK. Следовательно, оно более надежно, чем системное свойство « sun.arch.data.model ».

4. Вывод​

В этом уроке мы узнали, как проверить битовую версию JVM. Мы также наблюдали, как JNA упростила для нас решение на разных платформах.

Как всегда, полный код доступен на GitHub .

Источник

How to check if java is 64 bit

Otherwise if you are using Windows 7 you can check it by going to control panel and look there for Java icon. Folder Structure In case you do not have access to command prompt then determining the folder where Java. 32 Bit : 64 Bit : However during the installation it is possible that the user might change the installation folder.

How can I check whether on which mode(32 or 64 bit)is java runtime version is running

Your JRE mode depends on the browser mode you are running. Check this link to know about your browser version. That will be the version of your browser JRE. Otherwise if you are using Windows 7 you can check it by going to control panel and look there for Java icon. It will be mentioned there. If you are using XP, most probably the version is 32 bit.

How to find out if an installed Eclipse is 32 or 64 bit, Hit Ctrl + Alt + Del to open the Windows Task manager and switch to the processes tab. 32-bit programs should be marked with *32. Or hit Ctrl+Shift+ESC to launch Task Manager quicker. only if you are a windows user. @Gab — the question was referring to windows.

How to get a 64-bit java and how to know if your pc is 64

i show you how to get a 64-bit java and i also show you how to know if your computer is 64-bit or 32- bit and yeah. this is my first tutorial so please tell m

How do I detect 64-bit Java from the command line?

If you are using Sun’s VM (and I would suppose other VMs have similar details in their version information), you can check for the string «64-Bit» in the output of «java -version»:

java -version 2>&1 | find "64-Bit" >nul: if errorlevel 1 ( echo 32-Bit ) else ( echo 64-Bit ) 

jarnbjo’s script is for Windows. In Unix shell, you can use the following script.

#!/bin/sh BIT=`java -version 2>&1` case "$BIT" in *64-Bit*) echo "64-Bit" ;; *) echo "32-Bit" ;; esac

Here is a prewritten property dump program for you: linky

Check if Java is 64 bit or 32 bit, Check if Java is 64 or 32 using the java -version command. This is one of the simplest ways to check installed Java architecture. If you don’t want to write any code, simply open your terminal/command prompt and use this command. After running this command, it will print out all details along with Java architecture.

How to determine 32-bit OS or 64-bit OS from Java application [duplicate]

Should be available on all platforms, see the Java System Properties Tutorial for more information.

But 64 bit Windows platforms will lie to the JVM if it is a 32 bit JVM. Actually 64 bit Windows will lie to any 32 bit process about the environment to help old 32 bit programs work properly on a 64 bit OS. Read the MSDN article about WOW64 for more information.

As a result of WOW64, a 32 bit JVM calling System.getProperty(«os.arch») will return «x86». If you want to get the real architecture of the underlying OS on Windows, use the following logic:

String arch = System.getenv("PROCESSOR_ARCHITECTURE"); String wow64Arch = System.getenv("PROCESSOR_ARCHITEW6432"); String realArch = arch != null && arch.endsWith("64") || wow64Arch != null && wow64Arch.endsWith("64") ? "64" : "32"; 

This question was answered by ChrisH.

to retrieve the systems architecture. My Windows 64bit system will return amd64 as os.arch value.

Java — How can I tell if I’m running in 64-bit JVM or 32-bit, 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:

How do I detect whether 32-bit Java is installed on x64 Windows, only looking at the filesystem and registry?

This seems to provide the info on Windows:

1.) Open a windows command prompt.

2.) Key in: java -XshowSettings:all and hit ENTER.

3.) A lot of information will be displayed on the command window. Scroll up until you find the string: sun.arch.data.model .

4.) If it says sun.arch.data.model = 32 , your VM is 32 bit. If it says sun.arch.data.model = 64 , your VM is 64 bit.

Do you have access to the command prompt ?

Method 1 : Command Prompt

The specifics of the Java installed on the system can be determined by executing the following command java -version

Method 2 : Folder Structure

In case you do not have access to command prompt then determining the folder where Java.

32 Bit : C:\Program Files (x86)\Java\jdk1.6.0_30

64 Bit : C:\Program Files\Java\jdk1.6.0_25

However during the installation it is possible that the user might change the installation folder.

Method 3 : Registry

You can also see the version installed in registry editor.

  1. Go to registry editor
  2. Edit -> Find
  3. Search for Java. You will get the registry entries for Java.
  4. In the entry with name : DisplayName & DisplayVersion , the installed java version is displayed

Check this key for 32 bits and 64 bits Windows machines.

 HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment 

and this for Windows 64 bits with 32 Bits JRE.

 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment 

This will work for the oracle-sun JRE.

Java Program to Check if JVM is 32 or 64 bit, In Java, the getProperty () method is used to get information about various properties related to the system. Similarly, there two different approaches to check the bit of JVM by using System property “sun.arch.data.model” or “os. arch”. It will return either 32 bit or 64 bit based on your Java installation.

Источник

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