• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

how to read System Environment variables

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 76395
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic