What's an easy way to access System Property information?
Author: Deron Eriksson
Description: This Java tutorial describes how to use SystemUtils from Commons Lang to conveniently access System Property information.
Tutorial created using:
Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 2.0 (Eclipse 3.3.0)
The SystemUtils class in the Commons LangS library provides a large set of public static fields which allow for convenient access to System Property values. This comes in very handy if your IDE features code completion, like EclipseSW, shown below. ![]() In general, it can be fairly difficult to remember the particular name of a System property (to plug into System.getProperty()). However, SystemUtils plus code completion makes it unnecessary to memorize a bunch of System property names. The UserNameTest class is a simple example of using SystemUtils to get the current user name. UserNameTest.javapackage test; import org.apache.commons.lang.SystemUtils; public class UserNameTest { public static void main(String args[]) throws Exception { System.out.print("User name from SystemUtils: "); System.out.println(SystemUtils.USER_NAME); } } The output of UserNameTest is shown here. ResultsUser name from SystemUtils: Deron (Continued on page 2) Related Tutorials:
|