Operating System : OS « Development Class « Java






Operating System

        


/**
 * This file is distributed under the GPL
 * $Id: OperatingSystem.java 1869 2009-09-02 07:02:35Z scotta $
 */

//package net.bnubot.util;

import java.util.Properties;

/**
 * @author scotta
 */
public enum OperatingSystem {
  WINDOWS,
  OSX,
  LINUX,
  UNKNOWN;

  private static OperatingSystem initOS() {
    String osName = System.getProperty("os.name");
    if(osName.equals("Mac OS X"))
      return OSX;
    if(osName.startsWith("Windows "))
      return WINDOWS;
    if(osName.startsWith("Linux"))
      return LINUX;
    return UNKNOWN;
  }

  public static final OperatingSystem userOS = initOS();

  /**
   * @return user-displayable operating system version
   */
  public static String osVersion() {
    Properties p = System.getProperties();
    String osName = p.getProperty("os.name");
    String osVersion = p.getProperty("os.version");

    if((osVersion != null) && (osVersion.length() != 0))
      osName += " " + osVersion;

    switch(userOS) {
    case OSX:
      if(osVersion.startsWith("10.0"))
        osName += " Cheetah";
      else if(osVersion.startsWith("10.1"))
        osName += " Puma";
      else if(osVersion.startsWith("10.2"))
        osName += " Jaguar";
      else if(osVersion.startsWith("10.3"))
        osName += " Panther";
      else if(osVersion.startsWith("10.4"))
        osName += " Tiger";
      else if(osVersion.startsWith("10.5"))
        osName += " Leopard";
      else if(osVersion.startsWith("10.6"))
        osName += " Snow Leopard";
      break;
    case WINDOWS:
      osName += " " + p.getProperty("sun.os.patch.level");
      break;
    }

    osName += " (" + p.getProperty("os.arch") + ")";
    return osName;
  }

  public static String javaVersion() {
    return "Java " + System.getProperties().getProperty("java.version");
  }
}

   
    
    
    
    
    
    
    
  








Related examples in the same category

1.Class representing a standard operating system platform, WIN, MAC, or POSIX.
2.Get OS
3.Platform specific functionality.
4.Condition that tests the OS type.
5.Class to help determining the OS
6.Splits apart a OS separator delimited set of paths in a string into multiple Strings.
7.Get the operating systemGet the operating system
8.Get the OS
9.Virtual Machine Information (JVM)
10.Java Platform Information
11.Get OS Info
12.Platform Detector
13.OS detector
14.OS name