The Artima Developer Community
Sponsored Link

Java Buzz Forum
use Preferences API for App Settings

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Marc Logemann

Posts: 594
Nickname: loge
Registered: Sep, 2002

Marc Logemann is founder of www.logentis.de a Java consultancy
use Preferences API for App Settings Posted: May 7, 2004 5:33 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Marc Logemann.
Original Post: use Preferences API for App Settings
Feed Title: Marc's Java Blog
Feed URL: http://www.logemann.org/day/index_java.xml
Feed Description: Java related topics for all major areas. So you will see J2ME, J2SE and J2EE issues here.
Latest Java Buzz Posts
Latest Java Buzz Posts by Marc Logemann
Latest Posts From Marc's Java Blog

Advertisement

One of the most forgotten new APIs in JDK 1.4 is certainly the Preferences API. In fact, among other developers, i was also quite unaware of the Preferences API, up until the time where i wondered where the application settings of my own created J2SE application are stored (no, i am not totally weird, but i am using JGoodies as GUI framework and i was abstracted from the Preferences API)

So why trashing the old properties style of programming when it comes to application preferences (i am not talking about i18n issues)

- properties have no naming convention on the filesystem
- properties can only handle strings
- properties only work (without pains) in the filesystem
- properties have no means of hierarchy

With the the Preferences API you can easily export your preferences tree to an XML document or let the system decide where to put the data. The PreferenceFactory is responsible for deciding where to put the prefs. Because PreferencesFactory is an interface, there are different implementations based on the JRE. On Windows you have the java.util.prefs.WindowsPreferencesFactory which in fact stores the preferences into the registry. Of course of not having a registry, on linux there is some other implementation available.

If you would like to have some other backing store, you would have to implement the PreferencesFactory for yourself and modify the system property "java.util.prefs.PreferencesFactory" to point to your implementation. At least thats how i would start, i havnt done it yet and never read anything about implementing an own PreferencesFactory.

Give Preferences API a try. At least for J2SE developers this is a must, because its so much easier handling settings like "current application screen size" or "current theme" for your application.

Read: use Preferences API for App Settings

Topic: "Conversations" make things faster Previous Topic   Next Topic Topic: Groovy: what's in a name

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use