Boolean.getBoolean("myvariable"); // where myvariable has been defined in the
// Environment variable as Variable name:
// myvariable
// and Variable Value:true
The above call gives me output as false
.
If I use
System.getenv("myvariable") ;
then it gives me output as true
.
I am wondering why Boolean.getBoolean("myvariable")
is not working.
getenv() is for Operating System environment variables, whereas System. getProperty() is for JVM arguments which are passed as -DpropName=value to Java application launcher ( java ).
getenv(String name) method gets the value of the specified environment variable. An environment variable is a system-dependent external named value. Environment variables should be used when a global effect is desired, or when an external system interface requires an environment variable (such as PATH).
java - System. getenv() returns null when the environment variable exists - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.
Environment variables can never be a boolean, they are always a string (or not present).
System.getenv
returns an environment variable. That's not the same thing as System.getProperty
which returns a Java system property.
Boolean.getBoolean
uses the latter call, as documented:
Returns true if and only if the system property named by the argument exists and is equal to the string "true". [...] A system property is accessible through
getProperty
, a method defined by the System class.
Boolean.getBoolean("myvariable");
looks for a System Property called myvariable whereas System.getenv("myvariable");
looks for an environment variable. Though similar, they're not the same.
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