How to Check if Java is 64 bit or 32 bit

Mohammad Irfan Feb 02, 2024
  1. Check if Java is 64 or 32 using the System class
  2. Check if Java is 64 or 32 using the os.arch Token
  3. Check if Java is 64 or 32 using the java -version command
  4. Check if Java is 64 or 32 using Linux file command
  5. Check if Java is 64 or 32 using the jna library
  6. Check if Java is 64 or 32 using the Native class
How to Check if Java is 64 bit or 32 bit

This tutorial introduces the steps to check if the Java is 64 version or 32 version in Java.

To check whether the installed Java version is based on 64 or 32-bit, we can use several ways such as System.getProperty() method, Java version command, and sun.Platform class.

In this article, we will use these methods within the examples to check the Java platform.

Check if Java is 64 or 32 using the System class

In this example, we used getProperty() method of the System class that takes a string token as an argument and returns a string indicating to Java version architecture.

Here, we used sun.arch.data.model string that represents the internal model of Java. See the example below.

import java.io.IOException;
public class SimpleTesting {
  public static void main(String[] args) throws IOException {
    String is64 = System.getProperty("sun.arch.data.model");
    System.out.println("Your system supports " + is64 + " bit");
  }
}

Output:

Your system supports 64 bit

Check if Java is 64 or 32 using the os.arch Token

Here, we used os.arch token as an argument in getProperty() method of the System class. It returns the architecture type of Java. See the example below.

import java.io.IOException;
public class SimpleTesting {
  public static void main(String[] args) throws IOException {
    String is64 = System.getProperty("os.arch");
    System.out.println("Your system supports " + is64 + " bit");
  }
}

Output:

Your system supports amd64 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.

$ java - version

Output:

OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)

Check if Java is 64 or 32 using Linux file command

If you are working with Linux, then you can use the file command along with the path location of the installed Java, and you will get output as per the output below.

$ file{YOUR_JRE_LOCATION_HERE} / bin / java

Output:

ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2

Check if Java is 64 or 32 using the jna library

This is another solution that requires internal sun packages having architectural information. Here, we used the Platform class of the sun package that contains the is64Bit() method and returns true if Java is 64 type, false otherwise. See the example below.

The jna is a native API library used to connect with lower-level code.

import com.sun.jna.Platform;
import java.io.IOException;
public class SimpleTesting {
  public static void main(String[] args) throws IOException {
    boolean is64 = Platform.is64Bit();
    System.out.println("Your system supports is64 bit: " + is64);
  }
}

Output:

Your system supports is64 bit: true

Check if Java is 64 or 32 using the Native class

The Native class of jna package provides a constant POINTER_SIZE that returns the number of bytes Java arch uses. If it returns 8, then it means it is a 64-bit system, else 32. See the example below.

import com.sun.jna.Native;
import java.io.IOException;
public class SimpleTesting {
  public static void main(String[] args) throws IOException {
    boolean is64 = Native.POINTER_SIZE == 8;
    System.out.println("Your system supports is64 bit: " + is64);
  }
}

Output:

Your system supports is64 bit: true