Java Glossary : getEnv

CMP home Java glossary home Menu no menu Last updated 2004-06-28 by Roedy Green ©1996-2004 Canadian Mind Products

Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

You are here : home : Java Glossary : G words : getEnv.

getEnv
System.getEnv, to get at environment parameters, 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 4NT. 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 JDK 1.1. Make sure you use an upper case D.

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


CMP logo
CMP_home
home
Canadian Mind Products CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[24.87.56.253]
Your IP:[80.134.30.163]
You are visitor number 1928.
Please send errors, omissions and suggestions
to improve this page to Roedy Green.
You can get a fresh copy of this page from: or possibly from your local J: drive mirror:
http://mindprod.com/jgloss/getenv.html J:\mindprod\jgloss\getenv.html