search
HomeJavajavaTutorialJava program to check if JVM is 32-bit or 64-bit

Java program to check if JVM is 32-bit or 64-bit

Before writing a java program to check whether the JVM is 32-bit or 64-bit, let’s discuss the JVM first.

JVM is a java virtual machine, responsible for executing bytecode. It is part of the Java Runtime Environment (JRE). We all know that java is platform independent, but JVM is platform dependent. We need a separate JVM for each operating system. If we have the bytecode of any java source code, we can easily run it on any platform due to JVM. The entire process of java file execution is as follows -

  • First, we save the java source code with the extension .java, and the compiler converts it into bytecode with the extension .class. This happens at compile time.

  • Now, at runtime, the JVM reads and verifies the bytecode, allocates memory for variables, and then converts that bytecode into a machine-readable form.

We can check whether the JVM is 32-bit or 64-bit by using the two system properties "os.arch" and "sun.arch.data.model" in the java program. There is another way, we can check it through command line using "java --version".

Get attributes()

In this article, we will use this method to get the details of the JVM. It exists in system classes. It helps in retrieving system properties for specified parameters. Returns a string containing the value of the given parameter if the parameter exists, otherwise returns null.

grammar

System.getProperty(key); 

Here, "key" accepts parameters.

Method 1: Use os.arch

Example

public class Main {
   public static void main(String[] args) {
      String info = System.getProperty("os.arch");
      System.out.println(info + "-bit JVM is installed in your device ");
   }
}

Output

amd64-bit JVM is installed in your device

In the above code, we declare a string variable named "info" to store the value returned by the "getProperty()" method.

Method 2: Use sun.arch.data.model

Example

public class Main {
   public static void main(String[] args) {
      String info = System.getProperty("sun.arch.data.model");
      if (info.equals("64")) {
         System.out.println(info + "-bit JVM is installed in your device ");
      } else {
         System.out.println(info + "-bit JVM is installed in your device ");
      }
   }
}

Output

64-bit JVM is installed in your device

In the above code, we declare a string variable named "info" to store the value returned by the "getProperty()" method. In the if else block we check if the returned string is equal to "64" or not using the "equals()" method. The ‘equals()’ method is used to compare two strings. Its return type is a Boolean value that returns true if the two strings are equal, false otherwise. In this example, if block is true. Therefore, it prints 64-bit.

Method 3: Using the command line interface

Open cmd in your device and enter "java --version". When you press Enter, you'll see results based on your device's configuration -

C:\Users\Lenovo>java --version
java 17.0.6 2023-01-17 LTS
Java(TM) SE Runtime Environment (build 17.0.6+9-LTS-190)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.6+9-LTS-190, mixed mode, sharing)

in conclusion

The JVM is a platform-dependent machine that converts byte code into a machine-readable format. The main difference between 32-bit and 64-bit JVMs is the memory size limit. If it's 32-bit, we can specify a maximum of 4 GB, but 64-bit is much larger. In this article, we discussed two java programs to check whether a JVM is 32-bit or 64-bit.

The above is the detailed content of Java program to check if JVM is 32-bit or 64-bit. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:tutorialspoint. If there is any infringement, please contact admin@php.cn delete
How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?Mar 17, 2025 pm 05:46 PM

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?Mar 17, 2025 pm 05:45 PM

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?Mar 17, 2025 pm 05:44 PM

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?Mar 17, 2025 pm 05:43 PM

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

How does Java's classloading mechanism work, including different classloaders and their delegation models?How does Java's classloading mechanism work, including different classloaders and their delegation models?Mar 17, 2025 pm 05:35 PM

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools