getenv : Java Glossary
©1996-2017 Roedy Green of Canadian Mind Products
is not considered 100% kosher, but it will get you the
environment. It was deprecated in some JDK (Java Development Kit)
s, then later resurrected. On windows is it key names are case-insenstive, on other
platforms they are case-sensitive. The is no corresponding System. setenv, but you can set up the
environment for an execed process. getenv was deprecated for a while then reinstated.
The method is System.getenv( key ) not
Env( key ). The name violates the
usual conventions.Where System.getenv has been deprecated. What do
you do instead?
Use a properties file
This has the advantage of being platform
Use the <APPLET <PARAM tags
generate a Property. This only works for Applets.
Pass the parameters in on the command line
There are several ways of
doing this. These techniques only work in applications, not Applets.
Named parm technique
the string flavour=strawberry will appear as arg in your main method.
java.exe MyClass flavour=strawberry
Simple parm replacement technique
the string strawberry will appear as arg in your main method. The %
works in Windows, NT, 4DOS and tcc. You may need to do something slightly
different in other OSes (Operating Systems).
java.exe MyClass %flavour%
System property flavour with value "strawberry "" will be accessible via System.getProperty(flavour"); Make sure you put the
-D before your classname or else you will find -Dflavour=strawberry appearing at
arg instead. Contrary to rumour, this feature is also available in
Java version 1.6 or later. Make sure you use
an upper case
java.exe -Dflavour=%flavour% MyClass
Oracle’s Javadoc on System.getenv