• Post Reply Bookmark Topic Watch Topic
  • New Topic

System Properties  RSS feed

 
Lucky J Verma
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
  • 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
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!