• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

System Properties

 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have 2 Questions regarding Java System properties.

1 What is the exact different between getenv() and getProperties().On JDK 1.5 both work,but output seems to be different.

2. HOw can we get environment variables through getProperty()
I did java -Dusername=$USERNAME
but it says output $USERNAME
user.dir ,user.name....all work but these are not environmental varialbes but system properties taking values from environment variables.


thankx
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. With getenv(), you get environment variables that are set in the operating system that your program is running on. With getProperties(), you get Java system properties, which is something different than environment variables. You can set Java system properties on the command line with the -D switch:

java -Dmyproperty=value com.mycompany.MyClass

2. You cannot, because getProperty() is not for environment variables, but for Java system properties. Use getenv() if you need to access environment variables.
 
reply
    Bookmark Topic Watch Topic
  • New Topic