Is it possible to define processor architecture in java?

Is it possible to define processor architecture in java? e.g. x86 or SPARC sun etc.? If so, how do I do this?

+8
java cpu-architecture
source share
3 answers

You can try System.getenv () to get environment variables, use the PROCESSOR_ARCHITECTURE key to get CPU-architechture:

 System.out.println(System.getenv("PROCESSOR_ARCHITECTURE")); 

or in the case of 64 bits:

 System.out.println(System.getenv("PROCESSOR_ARCHITEW6432")); 

Another 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") , as it depends on the OS, as QMuhammad mentioned in his answer.

Pay attention to which :

System properties and environment variables are both conceptual mappings between names and values. Both mechanisms can be used to transfer user information to the Java process.

Relevant links:

+6
source share
 System.getProperty ("os.arch"); 

On my pc, amd64 returns.

+6
source share

To get the processor architecture, you can use the following property:

  System.getProperty("sun.cpu.isalist"); 

It returns "amd64" since I am using an Intel 64 bit processor and Intel 64 bit is using the amd architecture.

If you need the cost of an OS architecture, you can use this os.arch property

And if you need any other property, this can help you. I wrote the following snippet to get all the properties of the system:

  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); } } 
+4
source share

All Articles