getenv : Java Glossary

getenv
System.getenv 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 System.get Env( key ). The name violates the usual conventions.
Where System.getenv has been deprecated. What do you do instead?
  1. Use a properties file

    This has the advantage of being platform independent.
  2. Use the <APPLET <PARAM tags

    which generate a Property. This only works for Applets.
  3. 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[0] in your main method.
      java.exe MyClass flavour=strawberry
    • Simple parm replacement technique

      the string strawberry will appear as arg[0] in your main method. The % works in Windows, NT, 4DOS and tcc. You may need to do something slightly different in other OSes.
      set flavour=strawberry
      java.exe MyClass %flavour%
    • -D technique

      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[0] instead. Contrary to rumour, this feature is also available in Java version 1.6 or later. Make sure you use an upper case

      set flavour=strawberry
      java.exe -Dflavour=%flavour% MyClass

Learning More

Oracle’s Javadoc on System.getenv : available:

CMP homejump to top

available on the web at:

http://mindprod.com/jgloss/getenv.html
  

optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\getenv.html
logo
Please email your , letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email. If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, especially when sending an ad-hominem attack, a rant composed mainly of obscenities or a death threat, please quote the offending passage and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. I can’t very well fix erroneous or ambiguous text if I can’t find it.
Blog
IP:[65.110.21.43]
Your face IP:[54.234.67.55]
You are visitor number 17,384.