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:
- System.getenv() doc
- ChrisH's answer
- Why %processor_architecture% always returns x86 instead of AMD64
- Java's "os.arch" System Property is the Bitness of the JRE, NOT the
Operating System
- Finding out sytem architecture using Java