• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to read System Environment variables  RSS feed

 
Shahjehan Tariq
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Please guide can we set and get the own System Environment variables using java? if yes then how?

Thanks,
Shahjehan
 
Nikhil Goel
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use
System.getProperty(<<propertyname>>
System.setProperty(<<propertyname>>,<<value>> ;
 
Shahjehan Tariq
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is fine if we use it with in the same program. what if we want to read already set System Environment variable.

Thanks,
Shahjehan
 
JigaR Parekh
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.getProperty method has been deprecated in 1.4.2 and again activated in 1.5

so if you are using 1.4.2 the only solution is set those environment variable using -D argument of jvm.

assuming that you want to read variable from os level.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by JigaR Parekh:
System.getProperty method has been deprecated in 1.4.2 and again activated in 1.5

so if you are using 1.4.2 the only solution is set those environment variable using -D argument of jvm.

When a method is deprecated, you're discouraged to use it, because it might be removed in a later version (did that ever happen?) but it's possible to use it.
 
Campbell Ritchie
Marshal
Posts: 56209
171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think they ever remove methods or classes from newer versions (but am not sure). They have been back to older versions and re-engineered them to work better. The reason is that there are still people with legacy code around; if they remove old classes their code will no longer compile.

Even dangerous methods like Thread.stop() are still in the API for that reason.

A much commoner reason for deprecation is that a better method or class has been developed. But deprecated methods still work, if you don't mind the many warning messages.

CR
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!