Can you run 32 and 64 bit java

How to find if JVM is 32 or 64 bit from Java program? Example

You can find JVM bit sizes like 32 bit or 64 bit by using either running java command from the command prompt or by using System.getProperty() from Java program. The question is why do you want to know hardware or platform configuration while writing Java code which is supposed to write once and read anywhere(32 bit, 64 bit, etc)? Yes we don’t really need to know whether JVM is 32 bit or 64 bit more often but there are many situations when this matters

Читайте также:  Python exec bash command

Check if JVM is 32 or 64 bit from the Java program:

1. Since in 32 bit JVM maximum heap size in Java can not be more than 4GB (theoretically) if you can get JVM version from a script like running java command you can have a different memory configuration for your application. Also, if there are any specific JVM options which only applicable to 64 bit JVM than you can set those.

2. If your Java application is using native libraries then you certainly want to know whether Java running on the host is 32 bit or 64 bit because the native library may have different versions loaded for 32 bit or 64-bit architectures.

I am sure there could be some more practical reasons when you like to find JVM bit size or whether JVM is 64 bit or not

And, if you are serious about improving your advanced JVM skill and learn things like taking and analyzing heap dumps then you can also see these advanced courses for Java programmers to learn more about Performance and Memory managemen t including troubleshooting memory leaks in Java.

How to check if JVM is 32 or 64 bit in host

As I said earlier there are two different approaches either using Java system property like » sun.arch.data.model » or » os.arch » or by running java command from the script and checking its output for certain characters to identify whether JVM is 64 bit or not. let’s see an example of different ways to find if JVM is 32 bit or 64 bit:

Читайте также:  Package php pgsql has no installation candidate

1. By using System property sun.arch.data.model :

You can find whether your JVM is 32 bit or 64 bit by calling System.getProperty(«sun.arch.data.model») at least on Sun’s hotspot JVM. I don’t expect this to be run on any other Vendor-specific JVM but since most of the programmer or project uses Sun’s hotspot JVM. this is a handy option.

For 32 bit JVM » sun.arch.data.model » will be 32 and for 64 bit JVM, this would be 64. here is an example:

2. By using System.getProperty(« os.arch «)

» os.arch » is another System property that you can use to find whether installed JRE or JVM is 32 bit or 64 bit. by name, it sounds that it will return the operating system arch but you can still give it a try. Though I haven’t tested on all different JVM, I have read that it can indeed return JVM Bitness.

If you try this on a 64-bit machine and 32 bit JVM combination then please let us know what does it return. here is what it returns in the case of 32 bit JVM:

3. java -d64 -version

4. java -version

Plain old java -version reveals information about JVM bitness only if installed JRE is 64 bit, in case

of 32 bit JVM it doesn’t provide any information related to architecture but in the case of 64 bit JVM it

That’s all on how to find if JVM is 32 bit or 64 bit from Java program and command prompt. As I said it’s particularly useful if you have a dependency on native libraries which have a different build for 32 bit or 64-bit architecture. Let me know if you have some more ways to find JVM is 64 bit or not, you can also share on which scenario you need to know JVM bitness.

9 comments :

I wanted know whether my JVM is 64 bit or not and found your tips very relevant. I don’t require check if JVM is 32 bit but if any JVM is 64 bit than we do load native .so file from separate location.

Calling System.getProperty(«os.arch») on a 64-bit Linux system (OpenSUSE 11.4) with a 32-bit JVM returns: i386

I used Java(TM) SE Runtime Environment (build 1.6.0_22-b04)

Hi, We have several JDK and JRE installed on Solaris Sparc box, I want to find out which installed JDK or JRE is 64 bit ? Can you please share command to do that ? Also is it possible to run 32 bit JVM in 64 bit machine i.e. if My Solaris sparc box is 64 bit but JVM is 32 bit can I execute Java program there ?

One of the interesting point to know relate to 32 bit or 64 bit installation is that it varies on different environment e.g In windows and Linux you have separate installation for 32 bit and 64 bit JVM but on Solaris machine e.g. Sparc, one JVM installation represent both 32 bit and 64 bit JVM and until specified by -d32 and -d64, they by default run on 32 bit data model. Which means you may not able to assign more than 3.5GB of heap, despite running 64 bit JVM in 64 bit machine. Solution is use -d64 JVM option to run JVM on 64 bit data model.

How do i solve this error:
Could not create the java virtual machine
A fatal exception occurred. program will exit

I got «JVM Bit size: x86» for os.arch and «32bit» for sun.arch.data.model on my intel machine with 64 bit windows 7 os.

Just change the JRE to JDK 1.7.0_17, you will get the 64 bit JVM.

A nice tutorial on
JVM Architecture Specification Basic The Heap Area Introduction, teach about the JVM Heap Area in details
http://www.youtube.com/watch?v=c-A7ZzxjWUI

JVM Architecture Specification Basic The Method Area explained, teach about the JVM method area
http://www.youtube.com/watch?v=a5GzF2fSSCE

As this question is already answered and explained by Java geeks , I just want to add little extra in it — generally people prefer to switch over 64 but JVM when the existing heap space (1.5 to 1.8 M varies OS to OS) size provided by 32 bit JVM is not suffice for their application , but these days it is very common that people are migrating to 64 bit without understanding the requirement of applications.

Источник

Do I need 32-bit Java if I have 64-bit?

Note that because some web content may not work properly in a 64-bit browser, we recommend using the default 32-bit browser and downloading 32-bit Java.

Do you need 32 and 64-bit Java?

Java with 64 and/or 32 bit web browsers

Users that run Applets and Web Start applications through web browsers should choose the version of Java that matches their web browser. Generally speaking, 64 bit browsers run only 64 bit plugins and 32 bit browsers run only 32 bit plugins.

Why do I have Java 32-bit on my 64bit computer?

The most likely explanation is that you actually have both 32 bit and 64 bit versions of Java installed, and that some applications are using the 32 bit version, due to the way that they / your system is configured. You may not have explicitly installed 32 bit Java.

Can I install 32-bit Java on 64-bit Windows 10?

On Windows x86 (32-bit) systems, you can only install 32-bit JRE and/or JDK. However, on Windows x64 systems, you can install either 32-bit or 64-bit (or both) JRE and/or JDK.

What is the difference between 32-bit Java and 64-bit Java?

32-bits and 64-bits JVMs use different native data type sizes and memory-address spaces. 64-bits JVMs can allocate (can use) more memory than the 32-bits ones. 64-bits use native datatypes with more capacity but occupy more space. Because that, the same Object may occupy more space too.

How to Upgrade Your 32-Bit Java To a 64-Bit Java

Can I have both Java 32 and 64?

Yes, you can have both x64 bit and x32 bit Java installed. They won’t create conflicts with with each other, as they’re tied to the type of browser you’re using.

Is there a big difference between 32-bit and 64-bit?

Simply put, a 64-bit processor is more capable than a 32-bit processor because it can handle more data at once. A 64-bit processor can store more computational values, including memory addresses, which means it can access over 4 billion times the physical memory of a 32-bit processor. That’s just as big as it sounds.

What happens if I install 32-bit Windows 10 on a 64-bit machine?

Can I run 32-bit programs on a 64-bit computer? Most programs made for the 32-bit version of Windows will work on the 64-bit version of Windows except for most Antivirus programs. Device drivers that are made for the 32-bit version of Windows will not work correctly on a computer running a 64-bit version of Windows.

Источник

Difference between 32-bit and 64-bit JVM in Java?

One of the rather new or latest Java interview question is, «What is the difference between 32-bit and 64-bit JVM? or, How do you choose between 32-bit vs 64-bit JVM? or When to use 32-bit or 64-bit JVM? Some interviewer also use this concept to trick candidates by asking what would be the size of int variable in 32-bit and 64-bit Java? As mentioned in 130+ Java questions from last 5 years. Another tricky questions is, does same Java program can run on both 32-bit and 64-bit JVM? Short answer of this question is that Java is platform independent and same Java program will run absolutely fine in both 32-bit and 64-bit JVM. The real difference comes in addressable memory or heap memory.

In 32-bit JVM, the theoretical limit of maximum heap size is around 4G but practically you get way less than that e.g. around 1.5 GB in Windows and close to 3 GB in Solaris, see here why it’s like that.

Choosing a 64-bit JVM allows you to increase heap size beyond 4GB as addressable memory is way more now. But, it’s not all rosy because choosing 64-bit JVM and larger heap also has some disadvantages in terms of time required by Garbage Collectors and more memory needed by OOP pointers.

Difference between 32-bit and 64-bit JVM (Java Virtual Machine)

As I said before, main difference between these two JVM comes from addressable memory or heap size. In 32-bit JVM, the maximum addressable memory is 4GB but its way more in 64-bit JVM, around 2^64 . All other differences derives from this fact only.

64-bit JVM has bigger heap than 32-bit JVM. Maximum heap size for 32-bit JVM is much smaller than 64-bit JVM. theoretically its 4GB but practically on average its around 2GB. Specifying more heap will throw error JVM cannot created, invalid heap size.

OOP pointer size gets doubled in 64-bit JVM but you can use -XX:+UseCompressOops option to reduce the size of OOP pointer. This is the reason why same Java program will take more memory in 64-bit JVM than in 32-bit JVM.

Increased size of OOP pointer also means that less data can be cached in register that’s why its very important to enable -XX:+CompressOop JVM option when moving to 64 bit JVM.

Due to larger heap, GC pause time may increase, so the size of JVM heap must be decided properly to strike a balance between memory required and GC pause time.

Similarities between 32-bit and 64-bit JVM

As I said before, since Java is platform independent, same Java program will run fine in both 32-bit and 64-bit JVM. Java specification is also same for both 32-bit and 64-bit JVM e.g. size of all primitive variable like int, short, double, long and float is same i.e. int variable will take 4 bytes in both 32 and 64-bit JVM.

There is nothing like 32 or 64-bit Java. Though installation package for 32 and 64-bit JDK is different but Java specification is same. So, if you someone tries to trick you by saying that size of int variable will be double in 64-bit JVM then you can say no.

That’s all about difference between 32-bit and 64-bit JVM in Java. As I said, main difference is large heap memory available on 64-bit Java Virtual Machine and most people switch to 64-bit JVM for 2 reasons, a large heap and they are running their program on a 64-bit operating system.

Due to larger heap, Garbage collection can be long and that’s why you should allocate enough memory for your application to grow and don’t need to trigger Garbage collection until restart window kicks in. For example if your application is daily or weekly restart then just give it enough memory to run for the week without GC.

Thanks for reading this article so far. If you like my explanation of difference between 32-bit and 64-bit JVM in Java then please share this article on Facebook and Twitter or LinkedIn. If you have any doubt, feel free to ask questions on comments and if you want to learn more, you can also checkout these Java books and Java performance courses for further learning.

Источник

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