Many places suggest that the System.getenv()
JDK method has been deprecated. Many places suggest that it has been reinstated.
Is there a better API that provides the functionality to get environment settings in subsequent JDKs?
Or is System.getenv()
still the preferred way to get environment variables / properties?
System.getenv()
and System.getenv(String)
were introduced in the very early days of java, and then deprecated in Java 1.2(!).
Java 5 reinstated them (see bug 4199068), and since there's been no sign of these methods going anywhere or even being deprecated again for the last dozen years or so, I think it's safe to assume that they're here to stay, and use them as you need them.
In the Java 8 API docs the method is not deprecated. It has references to getenv(String)
but no other alternatives. Since getenv()
returns a Map<String,String>
from which you could just get(String)
you may as well just call getenv(String)
to get the value you are looking for else null
if it is not defined. As those API docs are authoritative you can conclude that getEnv()
is not deprecated in the current version Java nor is there a better recommended alternative other than getenv(String)
. Given that that API was introduced in Java 1.5 it is also highly backwards compatible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With