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.
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.