How are property files useful? I know property files are used to store config values and localization values. But why can't we have those values in Java class? What benefits does a property file give over Java files?
-
3Say you want to change the values without recompiling and rebuilting the entire application? Say you want people who don't have access to the source to be able to change properties? Say you change the properties/settings of your IDE, would you want to rebuild your IDE each time? – Peter Lawrey Oct 30 '16 at 20:12
-
1Possible duplicate of [Use of Property file](http://stackoverflow.com/questions/9872007/use-of-property-file) – Mick Mnemonic Oct 30 '16 at 20:16
-
1Sometimes you want to permanently store simple data, such as user preferences. You generally cannot overwrite your own program (and on multi-user systems doing so would be problematic), so it makes sense to store it in a file in a user-specific directory. And it has the advantage of being human-readable (at least, when the keys and values consist of ISO-8859-1 characters). – VGR Oct 30 '16 at 22:59
1 Answers
In general, property files are maintained in file system(Windows/Linux), but your class files are packaged as part of jar/war file. If you hardcode the values inside the classes, then you need to change the property value in the class, then recompile and repackage the jar/war file and test and redeploy the application.
why can't we have those values in Java class?
This is like hardcoding the values (inside class/jar/war) as you need to recompile the Java code and redeploy the application everytime a property value changes.
What benefits does a property file give over Java files?
You don't need to recompile the code, rather they can be updated from the property file (they reside outside class/jar/war) itself and you can restart the server/program.

- 21,832
- 11
- 51
- 67