我要评分
获取效率
正确性
完整性
易理解

CPU Architecture

  • Method 1:

    Use the System.getProperty method to obtain system-related attributes. Use System.getProperty("os.arch") to obtain information about the CPU architecture.

    Example:

    public class SystemProperty {  
        public static void main(String args[]) {     
        System.out.println("os_name:" + System.getProperty("os.name"));     
        System.out.println("os_arch:" + System.getProperty("os.arch"));      
    } 

    Execution result on the Kunpeng platform:

    [root@centos7 test]# Java SystemProperty
    os_name:Linux
    os_arch:aarch64
  • Method 2:

    Call the ManagementFactory.getOperatingSystemMXBean() method.

    Example:

    import Java.lang.management.ManagementFactory;
    import com.sun.management.OperatingSystemMXBean;
     
    public class SystemProperty {  
        public static void main(String args[]) {     
        OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementF
    actory.getOperatingSystemMXBean();
    String osArch = osmxb.getArch();
    System.out.println("osArch: " + osArch);      
    } 

    Execution result on the Kunpeng platform:

    [root@centos7 test]# Java SystemProperty
    osArch: aarch64