Name
Package java.util.prefs
Synopsis
The java.util.prefs
package contains classes and interfaces for managing persistant
user and
system-wide preferences for Java applications and classes. Most
applications will use only the Preferences
class
itself. Some will also use the event objects and listener interfaces
defined by this package, and some may need to explicitly catch the
types of exceptions defined by this package. Application programmers
never need to use the PreferencesFactory
interface
or the AbstractPreferences
class, which are
intended for Preferences implementors only.
To use the Preferences
class, first use a static
method to obtain an appropriate Preferences
object
or objects, and then use a get( )
method to query
a preference value or a put( )
method to set a
preference value. The code below shows a typical usage. See the
Preferences
class for details.
import java.util.prefs.Preferences; public class TextEditor { // some constants that define default values for preferences public static final int WIDTH_DEFAULT = 80; public static final String DICTIONARY_DEFAULT = ""; // Fields to be initialized from preference values public int width; // Screen width in columns public String dictionary; // Dictionary name for spell-checking public void initPrefs( ) { // Get Preferences objects for user and system preferences for this package Preferences userprefs = Preferences.userNodeForPackage(TextEditor.class); Preferences sysprefs = Preferences.systemNodeForPackage(TextEditor.class); ...
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.