Thursday, September 29, 2011

Favor Preferences over Properties

The java.util.prefs.Preferences API was introduced on JDK 1.4.2. Developers should use it instead of java.util.Properties to access or store configuration data.


The Preferences API provides sufficient built-in policy to prevent name clashes, foster consistency, and encourage robustness in the face of inaccessibility of the backing data store. It combines the power of JNDI and the simplicity of the java.util.Properties.

In Windows machine, the default backing data store for preferences is Windows Registry. You can configure the store to point to whatever store location you want.

If you're using Spring Framework in your project, you can use the PreferencesPlaceholderConfigurer instead of PropertyPlaceholderConfigurer.

The java.util.Properties is an old way of storing and accessing preferences =)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.