Getting Environment Variables


String envPath = System.getenv("PATH");



This phrase shows how you can retrieve an environment variable using the System.getenv() method. This method was deprecated in versions of JDK 1.2 through 1.4. In JDK 1.5, Sun did something that they don't do too often and they undeprecated this method. If you are using a version of the JDK that has this method deprecated, at compile time, you will get deprecation warnings if you attempt to use this method. A deprecated method is a method that should not be used in new development projects, but is supported for backward compatibility purposes. There is no guarantee that deprecated methods will continue to be supported in future versions of the JDK. But again, in the case of this method, in the most recent version of the JDK, 1.5, the method is not deprecated, so you can probably assume that it will indeed continue to be supported.

In general, it is usually considered a bad practice to rely on environment variables in your Java application. This is because environment variables are a platform-dependent concept, and Java strives to be platform independent. Some Java platforms, most notably the Macintosh, do not even have the concept of environment variables; thus in these environments, your code would not behave as expected. The next phrase describes how to get and set system properties. This approach is preferred over using environment variables.




JavaT Phrasebook. Essential Code and Commands
Java Phrasebook
ISBN: 0672329077
EAN: 2147483647
Year: 2004
Pages: 166

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net