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?
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.