"Java code slices" to determine system information such as operating systems

Source: Internet
Author: User

 /** JVM vendor info. */  public static final String  Jvm_vendor = system.getproperty ("Java.vm.vendor");  public static final  String jvm_version = system.getproperty ("Java.vm.version");  public static  Final string jvm_name = system.getproperty ("Java.vm.name");  /** the  Value of <tt>system.getproperty ("Java.version") </tt>. **/  public  Static final string java_version = system.getproperty ("Java.version");    /** the value of <tt>system.getproperty ("Os.name") </tt>. **/   public static final string os_name = system.getproperty ("Os.name");   /** true iff running on linux. */  public static final  boolean linuX = os_name.startswith ("Linux");   /** true iff running on windows .  */  public static final boolean windows = os_name.startswith (" Windows ");  /** true iff running on sunos. */  public  Static final boolean sun_os = os_name.startswith ("SunOS");   /** true  iff running on Mac OS X */  public static final  Boolean mac_os_x = os_name.startswith ("Mac os x");   /** true iff  running on freebsd */  public static final boolean free_bsd  = os_name.startswith ("FreeBSD");   public static final string os_arch  = system.getproperty ("Os.arch");   public static final string os_ Version = syStem.getproperty ("Os.version");   public static final string java_vendor =  system.getproperty ("Java.vendor");

The above code is excerpted from the Lucene org.apache.lucene.util.Constants class

Alternatively, you can use the following method:

private static String OS = System.getproperty ("Os.name"). toLowerCase ();/** * Determine if Windows * * @return */public static bool Ean Iswindows () {return os.indexof ("Win") >= 0;} public static Boolean Ismac () {return (Os.indexof ("Mac") >= 0);} public static Boolean Isunix () {return (Os.indexof ("Nix") >= 0 | | Os.indexof ("Nux") >= 0 | | Os.indexof ("Aix") > 0);} public static Boolean Issolaris () {return (Os.indexof ("SunOS") >= 0);}

The above code reference: http://www.java-gaming.org/index.php?topic=14110.0


Java code Slice to determine system information such as the operating system

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.