Java properties: .properties files vs xml?

Viewed 28742

I'm a newbie when it comes to properties, and I read that XML is the preferred way to store these. I noticed however, that writing a regular .properties file in the style of

foo=bar
fu=baz

also works. This would mean a lot less typing (and maybe easier to read and more efficient as well). So what are the benefits of using an XML file?

7 Answers

The disadvantages of XML:

  1. It is hard to read - the tags make it look busier than it really is
  2. The hierarchies and tags make it hard to edit and more prone to human errors
  3. It is not possible to "append" to an XML property file to introduce a new property or provide an overriding value for an existing property so that the last one wins. The ability to append a property can be very powerful - we can implement a property management logic around this so that certain properties are "hot" and we don't need to restart the instance when these change

The Java property file solves the above problems. Consistent naming conventions and dot notation can help in solving the issue of hierarchy.

Related