I wrote some programs in java, but I would like to know if they are 32 bit or 64 bit, by which I mean how would it run on a 32 bit computer, if it was 64 bit?
-
8you will just run it, unless you do something special java handles everything for you. Normal java code doesn't care if you run it on 64 or 32 bit jvm. – Oleg Aug 13 '17 at 14:53
-
4A Java program is neither 32 or 64 bit. It will run on either, provided there is a suitable JVM. – user207421 Aug 13 '17 at 15:01
4 Answers
I wrote some programs in java, but I would like to know if they are 32 bit or 64 bit
Neither. Your Java program is not specifically 32-bit or 64-bit.
All java programs should run on every up-to-date Java implementation.
When you compile a java program, it's turned into Java bytecode, which is often independent of what platform you compile it on and what platform you run it on.
This question should answer some questions for you: Java 32-bit vs 64-bit compatibility
Although a 64-bit Java implementation might handle some 64-bit operations better, there should be no difference as to how the program behaves (assuming you aren't using libraries that require 64-bit implementations).

- 303,325
- 100
- 852
- 1,154

- 468
- 1
- 7
- 18
Compiled Java programs are independent of the system architecture. In Case, If you want to check JVM bit size for some specific case you can use
System.out.println("JVM Bit size: " + System.getProperty("sun.arch.data.model"));

- 1,669
- 3
- 16
- 36
Its determined by the JRE. There exists 32 bit versions of the JRE and 64 bit versions.

- 11,452
- 7
- 53
- 68
generally we never write a code which we can say 32 bit or 64 bit. it actually depends on JRE and machine . rest of the things get managed by JVM and CPU.
for example if we use 64 bit primitives like long or double on 32 bit machine
then even assignment operation like long var = 10l;
will not be an atomic operation. it will happen in two phases of 32 bit.
but same assignment operation will be atomic operation in 64 bit.

- 415
- 3
- 13
-
You answer is the right one, you can add information from http://howtodoinjava.com/core-java/basics/difference-between-32-bit-java-vs-64-bit-java/ for future reference and completeness – Pfeiffer Aug 13 '17 at 15:07
-
1The read and write a value of long and double type is not atomic definitely at 64-bit jvm.The jvm not specify it.And the jls define:`For the purposes of the Java programming language memory model, a single writeto a non-volatile long or double value is treated as two separate writes: one to each32-bit half. An implementation of the Java VirtualMachine is free to perform writes to long and double values atomically or in two parts.`,and not require 32-bit or 64-bit – dabaicai Aug 13 '17 at 15:59
-
@Pfeiffer No, this Answer is not correct. **This Answer is very wrong.** Read the Java spec [17.7. Non-atomic Treatment of double and long](http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.7): It explicitly says that there is ***no* guarantee of atomic write to a `double` or `long`** unless marked `volatile`. A JVM implementation *may* perform an atomic write but no Java programmer should rely on that. If multithreaded, you must protect against an improper read of a half-written 64-bit number. – Basil Bourque Aug 13 '17 at 16:26
-