Our code uses a lot of system properties eg, ‘java.io.tmpdir’, ‘user.home’, ‘user.name’ etc. We do not have any constants defined for these anywhere (and neither does java I think) or any other clever thing for dealing with them so they are in plain text littered throughout the code.
String tempFolderPath = System.getProperty('java.io.tmpdir');
How is everyone using system properties?
I would treat this just as any other String constant you have scattered throughout your code and define a constant variable for it. Granted, in this case ‘java.io.tmpdir’ is unlikely to change, but you never know. (I don’t mean that Sun might change the meaning of ‘java.io.tmpdir’, or what system property it points to, but that you might change your mind about what system property you need to read.)
If you’re only using a particular property within one class, then I’d define the constants right in that class.
If you’re using the same properties in different classes, you may want to define an static class of your own to hold the constants you use most often.
Then, everywhere you need to use that constant just call it using