JVM Stands for Java Virtual Machine. It is an abstract computing machine that allows a computer to run a Java program. It is a platform-independent environment, responsible for compiling Java programs by performing conversion of Java code into machine language i.e. byte code. The memory needed by JVM to run a Java program is called heap memory.
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.
Method required : get.Property()
Syntax:
String System.getProperty( String key )
Parameter:
Key is the property of the operating system
Return Type
1) Returns a string containing the value of the property
2) Returns Null if the property does not exist
There are basically 3 methods to check whether the JVM is 32 bit or 64 bit:-
Using sun.arch.data.model
Java
// Java Program to check bitness of JVM by // using System property "sun.arch.data.model" public class checkBit { // get bitness of JVM private static final String a = System.getProperty( "sun.arch.data.model" ); public static void main(String[] args) { // printing the JVM version System.out.println( "JVM is " + a + " bit" ); } } |
Output:
Case 1: When JVM is 64 bit
Case 2: When JVM is 32 bit
Using os.arch.model
Java
// Java Program to check bitness of JVM by // using System property "os.arch.model" public class bit { // get bitness of JVM private static final String s = System.getProperty( "os.arch" ); public static void main(String[] args) { // printing the of what bit JVM is System.out.println( "JVM is " + s + " bit" ); } } |
Output:
Case 1: When JVM is 64 bit
Case 2: When JVM is 32 bit
Note: There is another approach to check the bits of JVM without Java program is by executing instruction ‘java -version’ in command prompt.
Case 1: When JVM is 64 bit
Case 2: When JVM is 32 bit