Know details about the JAVA at run-time (this howto is deprecated)Tag(s): DEPRECATED


Applets can read certain system properties by invoking System.getProperty(String key)
java.version       Java version number
java.vendor        Java vendor-specific string
java.vendor.url    Java vendor URL
os.name            Operating system name
os.arch            Operating system architecture
file.separator     File separator (eg, "/")
path.separator     Path separator (eg, ":")
line.separator     Line separator
java.class.version Java class version number 
But applets are prevented from reading these system properties (for security reason):
java.home          Java installation directory
java.class.path    Java classpath
user.name          User account name
user.home          User home directory
user.dir           User's current working directory
To read a system property from within an applet, simply invoke System.getProperty(key) on the property you are interested in.
String s = System.getProperty("java.vendor");
Here a dump that can be useful in a log file:
public String dump() {
    StringBuffer sb = new StringBuffer();
    Runtime rt = Runtime.getRuntime();

    long freeMemory = rt.freeMemory();
    long totalMemory = rt.totalMemory();

    sb.append("free memory=" + freeMemory); sb.append("\n");
    sb.append("total memory=" + totalMemory); sb.append("\n");

    java.util.Properties p = null;

    try {
      p = System.getProperties();
    }
    catch(Exception e) {
      e.printStackTrace();
      return "";
    }

    java.util.Enumeration en = p.propertyNames();

    while (en.hasMoreElements()){
      String s = (String) en.nextElement();
      String strValue= p.getProperty(s);
      sb.append(s + "=<" + strValue + ">"); sb.append("\n");
    }
    // result to a string
    return sb.toString();
}

blog comments powered by Disqus