BUILD ROBUST PORTABLE APPLICATIONS BY USING SYSTEM PROPERTIES Most developers would like their applications to run in as many different environments as possible but don't have the time or resources to do extensive testing across different platforms. One way to minimize the potential for problems on different operating systems is to use the properties available through the System class. The System class contains several property methods that provide information about the runtime environment for Java applications and idiosyncrasies of the underlying operating system. The following class will print out a complete list of all the available properties: import java.util.*; public class SysProps { public static void main(String[] args) { Enumeration sysProps = System.getProperties().propertyNames(); while(sysProps.hasMoreElements()) { String propName = (String)sysProps.nextElement(); System.out.println(propName+" : "+System.getProperty(propName)); } } } For example, to parse or create a file or directory path, the character used to separate directory or file names can be retrieved from the System property "file.separator" as in this code snippet: String fileNameDelimiter = System.getProperty("file.separator"); On a Windows system, fileNameDelimiter would consist of the backslash (\) character, UNIX systems would return the forward slash (/), and MacOS systems a colon (:). Rather than hard-coding these values, an application can retrieve the property value at runtime and build up or parse file paths properly without prior knowledge about the current operating system. Of course, file paths are just a subset of the potential problems encountered when running Java applications on multiple platforms, but using as much dynamic information as possible about the underlying runtime context can help extend the portability of Java applications into untested or even unknown environments. System properties are a great way to increase portability with a minimum of effort.