tags:

views:

49

answers:

2

.Net assembly PE Header has a target platform for 32-bit / 64-bit which is used when the assembly use native interop like p/invoke (other wise it would be Target=AnyCPU)

Is there any equivalent for Java when the Java application has an interface to some native interface through JNI? The JNI has to be either compiled for 32 or 64 bit

Is there an article explaining Java 64-bit architecutre and development? I wasn't able to find one

Thanks!

+1  A: 

You can detect 64 bit by using:

public static final boolean is64bit = (System.getProperty("sun.arch.data.model").indexOf("64") != -1)

you can also start java in 32 or 64 bit by using -d32 or -d64.

is this for a web or desktop app. there may be a way of specifying it from the manifest file

That's a Sun-specific and undocumented system property, it might not work on other JVM implementations or on future Oracle Java versions.
Jesper
I am not looking to determine what platform I am running on. My question is whether I can mark my code that it is not compatible with 32-bit so it wouldn't run on 32-bit Java impl.Of course this can be manually implemented with your suggested technique
Saar
A: 

You can look at the system property os.arch:

String osArch = System.getProperty("os.arch");

Unfortunately the possible values for this property are not documented, but you might try it out on different systems to see what it returns (using Sun JDK 6 update 20 on my 64-bit system it returns amd64).

See the API documentation of java.lang.System.getProperties() for other available system properties.

Jesper