With JDK 1.4 Java has expanded on its Properties class and now provides a Preferences API. This is the product of JSR-10 (Java Specification Request) ''Preferences API Specification: A simple API allowing programs to manipulate user preference data and configuration data'', and is a substantial improvement on the Preferences functionality.

Part of the reason I'm looking into this is that given it provides a hierarchical preferences model, it might suit the needs of WikiFarms (see MultipleWikis, MultiWikiDevelopment, IdeasMultipleWikiWebs), since it would be possible to share both system configuration and user-level information across multiple wiki. -- MurrayAltheim


!! Overview 

''[[this overview c/o Sun's J2SE documentation]''

Applications require preference and configuration data to adapt to the needs of different users and environments. The java.util.prefs package provides a way for applications to store and retrieve user and system preference and configuration data. The data is stored persistently in an implementation-dependent backing store. There are two separate trees of preference nodes, one for user preferences and one for system preferences.

All of the methods that modify preference data are permitted to operate asynchronously. They may return immediately, and changes will eventually propagate to the persistent backing store. The flush method can be used to force updates to the backing store.

The methods in the [Preferences class| http://java.sun.com/j2se/1.5.0/docs/api/java/util/prefs/Preferences.html] may be invoked concurrently by multiple threads in a single JVM without the need for external synchronization, and the results will be equivalent to some serial execution. If this class is used concurrently by multiple JVMs that store their preference data in the same backing store, the data store will not be corrupted, but no other guarantees are made concerning the consistency of the preference data.

For more details, choose from the following links:

* [Comparing Preferences API to Other Mechanisms | http://java.sun.com/j2se/1.5.0/docs/guide/preferences/index.html#prefs-other]
* [Usage Notes | http://java.sun.com/j2se/1.5.0/docs/guide/preferences/index.html#prefs-usage]
* [Design FAQ | http://java.sun.com/j2se/1.5.0/docs/guide/preferences/index.html#prefs-design-faq]

[[end of Sun's ''Overview'']

!! Notes on "Implementation"

The J2SE includes documentation and information about the persistent storage implementation, but that's all directed at implementors at the J2SE level. Every J2SE implementation must have an implementation (and does, apparently). This seems to confuse some people: there's no reason why any developer ''using'' the Preferences API would need to either replace those implementations unless one were developing software for an OS that didn't already have a J2SE available; the whole point of the Preferences API was to simplify this stuff (for developers) not make it more complicated. Only if one were developing a J2SE implementation would you need to pay attention to this. There's a note in bold in the javadocs for java.util.prefs.~PreferencesFactory:
%%blockquote
This class is for Preferences implementers only. Normal users of the Preferences facility should have no need to consult this documentation. 
%%

The Preferences API permits XML import and export of preference data. The DTD is posted as part of the javadocs
for the java.util.prefs.Preferences class. There are methods for both importing and exporting the XML using

; {{importPreferences(~InputStream is)}} : Imports all of the preferences represented by the XML document on the specified input stream.
; {{exportNode(~OutputStream os)}} : Emits on the specified output stream an XML document representing all of the preferences contained in this node (but not its descendants).
; {{exportSubtree(~OutputStream os)}} : Emits an XML document representing all of the preferences contained in this node and all of its descendants.

but normally developers wouldn't even have to deal with these unless one wanted to control where the J2SE implementation was storing the prefs, e.g., to permit the XML to be hand-edited.

%%blockquote
This class contains an export/import facility, allowing preferences to be "exported" to an XML document, and XML documents representing preferences to be "imported" back into the system. This facility may be used to back up all or part of a preference tree, and subsequently restore from the backup.
%%


!! Specification/Documentation

* [JSR 10: Preferences API Specification | 
http://jcp.org/en/jsr/detail?id=10] ''A simple API allowing programs to manipulate user preference data and configuration data'', Java Community Process, Final Release 9 May 2002
* [Preferences API Guide in J2SE 1.4.2 | http://java.sun.com/j2se/1.4.2/docs/guide/lang/preferences.html]
* [Preferences API Guide in J2SE 1.5 | http://java.sun.com/j2se/1.5.0/docs/guide/preferences/index.html]
* [Preferences API Javadoc | http://java.sun.com/j2se/1.4.2/docs/api/java/util/prefs/package-summary.html]


!! Articles and Projects

* [The Preferences API in Java 2SE 1.4 (Merlin) | http://www.onjava.com/pub/a/onjava/synd/2001/10/17/j2se.html] by Jeff Brown, ONJava.com, 17 Oct 2001
* [Store objects using the Preferences API | http://www-128.ibm.com/developerworks/library/j-prefapi.html], by Greg Travis, IBM ~DeveloperWorks, 14 Oct 2003
* [Sir, what is your preference? | http://www.javaworld.com/javaworld/jw-08-2001/jw-0831-preferences.html] ''Manage your application's preferences with J2SE 1.4's new Preferences API'', by Ray Djajadinata, ~JavaWorld.com, 31 Aug 2001
* [Using the Preferences API and Interfaces and Constants | http://java.sun.com/developer/JDCTechTips/2003/tt0715.html] ''Technical Articles and Tips'', Sun Developer Network, 15 July 2003
* [Magic with Merlin: Working with preferences | http://www.ibm.com/developerworks/java/library/j-mer1002/] ''JSR 10, the Preferences API Specification, allows for the manipulation of preference and configuration data'', by John Zukowski, IBM ~DeveloperWorks, 1 Oct 2001
* [Projects:GConf Preferences Module | http://www.limasoftware.net/wiki/index.php?title=Projects:GConf_Preferences_Module], a GConf based preference backend for the java platform (GPL)



----

! Discussion

...