Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML vs Properties File

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which do you use for storing user settings, global settings, values, etc and why one over the other?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A properties file is much easier to use when you have a small, fixed set of settings with a plain structure.
An XML file implies more work, but is more appropriate to handle complex hierarchical settings.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are comfortable with going for a simple solution first, and only adding extra complexity later if you really need it, then start with a Properties file (or, even bettter, a hard-coded Map).
As long as you have some sort of "facade" through which you access these settings, then it shouldn't matter to the calling code which one you use. Then you are free to use hard-coded default values, load from a properties file, read some XML, run a database query, look them up in a JNDI repository, access a web service etc. etc.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic