Is it possible to detect processor architecture in java? like x86 or sun SPARC, etc? If so, how would I go about doing it?
-
Which OS? would reading certain files like /proc/cpuinfo on linux help? – CloudyMarble Mar 06 '13 at 07:12
-
@TwoMore: Solaris and windows mostly – shawn Mar 06 '13 at 07:13
-
@shawn then you better use a platform undependent solution using pure java, see answer below. – CloudyMarble Mar 06 '13 at 07:17
-
1This q was closed as a duplicate, however the linked question is not asking about processor architecture specifically. Don't go there, but read some of the answers for better information. – theMayer Feb 21 '20 at 21:43
-
@theMayer: Exactly. Way to make the site more disorganized. I had the same question but couldn't reply here. See my answer [here](https://stackoverflow.com/a/73582584/1021943) for a solution making use of `commons-lang3`. – Priidu Neemre Sep 03 '22 at 05:14
3 Answers
You can try the System.getenv() to get environment variables, use the PROCESSOR_ARCHITECTURE
Key to get the CPU-architechture:
System.out.println(System.getenv("PROCESSOR_ARCHITECTURE"));
or in case of 64 bit:
System.out.println(System.getenv("PROCESSOR_ARCHITEW6432"));
The other way would be to use the "os.arch" system property:
System.getProperty("os.arch");
and you may need to get the OS before using System.getProperty("os.name")
since this is OS dependent as QMuhammad mentioned in his answer.
Notice that:
System properties and environment variables are both conceptually mappings between names and values. Both mechanisms can be used to pass user-defined information to a Java process.
Relevant links:

- 1
- 1

- 36,908
- 70
- 97
- 130
-
2This works only on MS Windows, and only on certain versions of MS Windows. – Mikhail Vladimirov Mar 06 '13 at 07:21
-
@MikhailVladimirov I edited my answer, but its pretty interesstign what you mentioned, thought this would be platform undependent – CloudyMarble Mar 06 '13 at 07:35
-
At least this is described in official specification: http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#getProperties%28%29 – Mikhail Vladimirov Mar 06 '13 at 07:41
-
-
1
System.getProperty ("os.arch");
On my PC returns amd64
.

- 13,572
- 1
- 38
- 40
-
This doesnt seem to work properly in some cases of 64 bit Windows with 32 bit JVM process see this: http://stackoverflow.com/a/5940770/395659 – CloudyMarble Mar 06 '13 at 07:26
You can use following property to get processor architecture:
System.getProperty("sun.cpu.isalist");
It returns "amd64" as i am using Intel's 64 bit processor and Intel 64 bit uses amd architecture.
If you need OS architecture value you can use this property "os.arch"
And if you need any other property then this might help you. I wrote following snippet to get all system properties:
public static void main(String[] args) {
Properties props = System.getProperties();
Enumeration<Object> keys = props.keys();
while(keys.hasMoreElements()){
Object key = keys.nextElement();
Object value = props.get(key);
System.out.println("Key: "+key + " Value: "+value);
}
}

- 567
- 6
- 14
-
1Property `sun.cpu.isalist` is not standard. You better use standard `os.arch` property. – Mikhail Vladimirov Mar 06 '13 at 07:23
-
1I mentioned both so both can work. Moreover "sun.cpu.isalist" is not set on Linux, but it is set on Solaris and Windows. Depends upon which platform you are working on. – Muhammad Haris Altaf Mar 06 '13 at 07:34