The java.lang.System class defines a number of well-known properties.
For example, you can obtain the JVM's temporary directory by looking up the "java.io.tmpdir" property:
... = System.getProperty("java.io.tmpdir");
What I don't understand is why these properties aren't defined as constants (e.g. in the java.lang.System class). This would be a lot less error-prone than using literal Strings. In other words, I would like to be able to do this:
... = System.getProperty(System.JAVA_IO_TMPDIR);
Any ideas why this wasn't done? It could even be added in a future release of Java without breaking backward compatibility. Or am I missing something obvious?
All the properties documented under System.getProperties() are standardised - every Java SE implementation must provide them. There is no reason that Java 7 could not introduce constants for these standard property names. It would not prevent the introduction of new properties. I think it's just no one has thought it worth the effort (even trivial additions to core Java APIs have to go through processes I think).
My guess is that Sun did not want to commit to a predefined set of system properties. If they are not defined as contants they can add system properties at any time (even if they only release an incremental version of the JDK like from 1.4.1 to 1.4.2).
Edit:
Any predefined constants must be considered part of the API. Thus even changing the number of constants is an API change. By not defining any constants Sun is allowed to define new system properties without introducing an API change.
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