1 *java.util.prefs.Preferences* *Preferences* A node in a hierarchical collection
3 public abstract class Preferences
4 extends |java.lang.Object|
6 |java.util.prefs.Preferences_Description|
7 |java.util.prefs.Preferences_Fields|
8 |java.util.prefs.Preferences_Constructors|
9 |java.util.prefs.Preferences_Methods|
11 ================================================================================
13 *java.util.prefs.Preferences_Fields*
14 |int_java.util.prefs.Preferences.MAX_KEY_LENGTH|
15 |int_java.util.prefs.Preferences.MAX_NAME_LENGTH|
16 |int_java.util.prefs.Preferences.MAX_VALUE_LENGTH|
18 *java.util.prefs.Preferences_Constructors*
19 |java.util.prefs.Preferences()|Sole constructor.
21 *java.util.prefs.Preferences_Methods*
22 |java.util.prefs.Preferences.absolutePath()|Returns this preference node's abso
23 |java.util.prefs.Preferences.addNodeChangeListener(NodeChangeListener)|Register
24 |java.util.prefs.Preferences.addPreferenceChangeListener(PreferenceChangeListener)|
25 |java.util.prefs.Preferences.childrenNames()|Returns the names of the children
26 |java.util.prefs.Preferences.clear()|Removes all of the preferences (key-value
27 |java.util.prefs.Preferences.exportNode(OutputStream)|Emits on the specified ou
28 |java.util.prefs.Preferences.exportSubtree(OutputStream)|Emits an XML document
29 |java.util.prefs.Preferences.flush()|Forces any changes in the contents of this
30 |java.util.prefs.Preferences.get(String,String)|Returns the value associated wi
31 |java.util.prefs.Preferences.getBoolean(String,boolean)|Returns the boolean val
32 |java.util.prefs.Preferences.getByteArray(String,byte[])|Returns the byte array
33 |java.util.prefs.Preferences.getDouble(String,double)|Returns the double value
34 |java.util.prefs.Preferences.getFloat(String,float)|Returns the float value rep
35 |java.util.prefs.Preferences.getInt(String,int)|Returns the int value represent
36 |java.util.prefs.Preferences.getLong(String,long)|Returns the long value repres
37 |java.util.prefs.Preferences.importPreferences(InputStream)|Imports all of the
38 |java.util.prefs.Preferences.isUserNode()|Returns true if this preference node
39 |java.util.prefs.Preferences.keys()|Returns all of the keys that have an associ
40 |java.util.prefs.Preferences.name()|Returns this preference node's name, relati
41 |java.util.prefs.Preferences.node(String)|Returns the named preference node in
42 |java.util.prefs.Preferences.nodeExists(String)|Returns true if the named prefe
43 |java.util.prefs.Preferences.parent()|Returns the parent of this preference nod
44 |java.util.prefs.Preferences.put(String,String)|Associates the specified value
45 |java.util.prefs.Preferences.putBoolean(String,boolean)|Associates a string rep
46 |java.util.prefs.Preferences.putByteArray(String,byte[])|Associates a string re
47 |java.util.prefs.Preferences.putDouble(String,double)|Associates a string repre
48 |java.util.prefs.Preferences.putFloat(String,float)|Associates a string represe
49 |java.util.prefs.Preferences.putInt(String,int)|Associates a string representin
50 |java.util.prefs.Preferences.putLong(String,long)|Associates a string represent
51 |java.util.prefs.Preferences.remove(String)|Removes the value associated with t
52 |java.util.prefs.Preferences.removeNode()|Removes this preference node and all
53 |java.util.prefs.Preferences.removeNodeChangeListener(NodeChangeListener)|Remov
54 |java.util.prefs.Preferences.removePreferenceChangeListener(PreferenceChangeListener)|
55 |java.util.prefs.Preferences.sync()|Ensures that future reads from this prefere
56 |java.util.prefs.Preferences.systemNodeForPackage(Class<?>)|Returns the prefere
57 |java.util.prefs.Preferences.systemRoot()|Returns the root preference node for
58 |java.util.prefs.Preferences.toString()|Returns a string representation of this
59 |java.util.prefs.Preferences.userNodeForPackage(Class<?>)|Returns the preferenc
60 |java.util.prefs.Preferences.userRoot()|Returns the root preference node for th
62 *java.util.prefs.Preferences_Description*
64 A node in a hierarchical collection of preference data. This class allows
65 applications to store and retrieve user and system preference and configuration
66 data. This data is stored persistently in an implementation-dependent backing
67 store. Typical implementations include flat files, OS-specific registries,
68 directory servers and SQL databases. The user of this class needn't be
69 concerned with details of the backing store.
71 There are two separate trees of preference nodes, one for user preferences and
72 one for system preferences. Each user has a separate user preference tree, and
73 all users in a given system share the same system preference tree. The precise
74 description of "user" and "system" will vary from implementation to
75 implementation. Typical information stored in the user preference tree might
76 include font choice, color choice, or preferred window location and size for a
77 particular application. Typical information stored in the system preference
78 tree might include installation configuration data for an application.
80 Nodes in a preference tree are named in a similar fashion to directories in a
81 hierarchical file system. Every node in a preference tree has a node name
82 (which is not necessarily unique), a unique absolute path name, and a path name
83 relative to each ancestor including itself.
85 The root node has a node name of the empty string (""). Every other node has an
86 arbitrary node name, specified at the time it is created. The only restrictions
87 on this name are that it cannot be the empty string, and it cannot contain the
88 slash character ('/').
90 The root node has an absolute path name of "/". Children of the root node have
91 absolute path names of "/" + <node name>. All other nodes have absolute path
92 names of <parent's absolute path name> + "/" + <node name>. Note that all
93 absolute path names begin with the slash character.
95 A node n's path name relative to its ancestor a is simply the string that must
96 be appended to a's absolute path name in order to form n's absolute path name,
97 with the initial slash character (if present) removed. Note that:
99 No relative path names begin with the slash character. Every node's path name
100 relative to itself is the empty string. Every node's path name relative to its
101 parent is its node name (except for the root node, which does not have a
102 parent). Every node's path name relative to the root is its absolute path name
103 with the initial slash character removed.
107 No path name contains multiple consecutive slash characters. No path name with
108 the exception of the root's absolute path name ends in the slash character. Any
109 string that conforms to these two rules is a valid path name.
111 All of the methods that modify preferences data are permitted to operate
112 asynchronously; they may return immediately, and changes will eventually
113 propagate to the persistent backing store with an implementation-dependent
114 delay. The flush method may be used to synchronously force updates to the
115 backing store. Normal termination of the Java Virtual Machine will not result
116 in the loss of pending updates -- an explicit flush invocation is not required
117 upon termination to ensure that pending updates are made persistent.
119 All of the methods that read preferences from a Preferences object require the
120 invoker to provide a default value. The default value is returned if no value
121 has been previously set or if the backing store is unavailable. The intent is
122 to allow applications to operate, albeit with slightly degraded functionality,
123 even if the backing store becomes unavailable. Several methods, like flush,
124 have semantics that prevent them from operating if the backing store is
125 unavailable. Ordinary applications should have no need to invoke any of these
126 methods, which can be identified by the fact that they are declared to throw
127 (|java.util.prefs.BackingStoreException|) .
129 The methods in this class may be invoked concurrently by multiple threads in a
130 single JVM without the need for external synchronization, and the results will
131 be equivalent to some serial execution. If this class is used concurrently by
132 multiple JVMs that store their preference data in the same backing store, the
133 data store will not be corrupted, but no other guarantees are made concerning
134 the consistency of the preference data.
136 This class contains an export/import facility, allowing preferences to be
137 "exported" to an XML document, and XML documents representing preferences to be
138 "imported" back into the system. This facility may be used to back up all or
139 part of a preference tree, and subsequently restore from the backup.
141 The XML document has the following DOCTYPE declaration:
143 <!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd">
145 Note that the system URI (http://java.sun.com/dtd/preferences.dtd) is not
146 accessed when exporting or importing preferences; it merely serves as a string
147 to uniquely identify the DTD, which is:
149 <?xml version="1.0" encoding="UTF-8"?>
151 <!-- DTD for a Preferences tree. -->
153 <!-- The preferences element is at the root of an XML document representing a
154 Preferences tree. --> <!ELEMENT preferences (root)>
156 <!-- The preferences element contains an optional version attribute, which
157 specifies version of DTD. --> <!ATTLIST preferences EXTERNAL_XML_VERSION CDATA
160 <!-- The root element has a map representing the root's preferences (if any),
161 and one node for each child of the root (if any). --> <!ELEMENT root (map,
164 <!-- Additionally, the root contains a type attribute, which specifies whether
165 it's the system or user root. --> <!ATTLIST root type (system|user) #REQUIRED >
167 <!-- Each node has a map representing its preferences (if any), and one node
168 for each child (if any). --> <!ELEMENT node (map, node*) >
170 <!-- Additionally, each node has a name attribute --> <!ATTLIST node name CDATA
173 <!-- A map represents the preferences stored at a node (if any). --> <!ELEMENT
176 <!-- An entry represents a single preference, which is simply a key-value pair.
177 --> <!ELEMENT entry EMPTY > <!ATTLIST entry key CDATA #REQUIRED value CDATA
180 Every Preferences implementation must have an associated
181 (|java.util.prefs.PreferencesFactory|) implementation. Every Java(TM) SE
182 implementation must provide some means of specifying which PreferencesFactory
183 implementation is used to generate the root preferences nodes. This allows the
184 administrator to replace the default preferences implementation with an
185 alternative implementation.
187 Implementation note: In Sun's JRE, the PreferencesFactory implementation is
192 If the system property java.util.prefs.PreferencesFactory is defined, then it
193 is taken to be the fully-qualified name of a class implementing the
194 PreferencesFactory interface. The class is loaded and instantiated; if this
195 process fails then an unspecified error is thrown.
197 If a PreferencesFactory implementation class file has been installed in a jar
198 file that is visible to the system class loader(|java.lang.ClassLoader|) , and
199 that jar file contains a provider-configuration file named
200 java.util.prefs.PreferencesFactory in the resource directory META-INF/services,
201 then the first class name specified in that file is taken. If more than one
202 such jar file is provided, the first one found will be used. The class is
203 loaded and instantiated; if this process fails then an unspecified error is
206 Finally, if neither the above-mentioned system property nor an extension jar
207 file is provided, then the system-wide default PreferencesFactory
208 implementation for the underlying platform is loaded and instantiated.
214 *int_java.util.prefs.Preferences.MAX_KEY_LENGTH*
216 Maximum length of string allowed as a key (80 characters).
219 *int_java.util.prefs.Preferences.MAX_NAME_LENGTH*
221 Maximum length of a node name (80 characters).
224 *int_java.util.prefs.Preferences.MAX_VALUE_LENGTH*
226 Maximum length of string allowed as a value (8192 characters).
230 *java.util.prefs.Preferences()*
232 protected Preferences()
234 Sole constructor. (For invocation by subclass constructors, typically
238 *java.util.prefs.Preferences.absolutePath()*
240 public abstract |java.lang.String| absolutePath()
242 Returns this preference node's absolute path name.
246 Returns: this preference node's absolute path name.
248 *java.util.prefs.Preferences.addNodeChangeListener(NodeChangeListener)*
250 public abstract void addNodeChangeListener(java.util.prefs.NodeChangeListener ncl)
252 Registers the specified listener to receive node change events for this node. A
253 node change event is generated when a child node is added to or removed from
254 this node. (A single (|java.util.prefs.Preferences|) invocation results in
255 multiple node change events, one for every node in the subtree rooted at the
258 Events are only guaranteed for changes made within the same JVM as the
259 registered listener, though some implementations may generate events for
260 changes made outside this JVM. Events may be generated before the changes have
261 become permanent. Events are not generated when indirect descendants of this
262 node are added or removed; a caller desiring such events must register with
265 Few guarantees can be made regarding node creation. Because nodes are created
266 implicitly upon access, it may not be feasible for an implementation to
267 determine whether a child node existed in the backing store prior to access
268 (for example, because the backing store is unreachable or cached information is
269 out of date). Under these circumstances, implementations are neither required
270 to generate node change events nor prohibited from doing so.
273 ncl - The NodeChangeListener to add.
275 *java.util.prefs.Preferences.addPreferenceChangeListener(PreferenceChangeListener)*
277 public abstract void addPreferenceChangeListener(java.util.prefs.PreferenceChangeListener pcl)
279 Registers the specified listener to receive preference change events for this
280 preference node. A preference change event is generated when a preference is
281 added to this node, removed from this node, or when the value associated with a
282 preference is changed. (Preference change events are not generated by the
283 (|java.util.prefs.Preferences|) method, which generates a node change event.
284 Preference change events are generated by the clear method.)
286 Events are only guaranteed for changes made within the same JVM as the
287 registered listener, though some implementations may generate events for
288 changes made outside this JVM. Events may be generated before the changes have
289 been made persistent. Events are not generated when preferences are modified in
290 descendants of this node; a caller desiring such events must register with each
294 pcl - The preference change listener to add.
296 *java.util.prefs.Preferences.childrenNames()*
298 public abstract |java.lang.String|[] childrenNames()
299 throws |java.util.prefs.BackingStoreException|
301 Returns the names of the children of this preference node, relative to this
302 node. (The returned array will be of size zero if this node has no children.)
306 Returns: the names of the children of this preference node.
308 *java.util.prefs.Preferences.clear()*
310 public abstract void clear()
311 throws |java.util.prefs.BackingStoreException|
313 Removes all of the preferences (key-value associations) in this preference
314 node. This call has no effect on any descendants of this node.
316 If this implementation supports stored defaults, and this node in the
317 preferences hierarchy contains any such defaults, the stored defaults will be
318 "exposed" by this call, in the sense that they will be returned by succeeding
323 *java.util.prefs.Preferences.exportNode(OutputStream)*
325 public abstract void exportNode(java.io.OutputStream os)
326 throws |java.util.prefs.BackingStoreException|
327 |java.io.IOException|
329 Emits on the specified output stream an XML document representing all of the
330 preferences contained in this node (but not its descendants). This XML document
331 is, in effect, an offline backup of the node.
333 The XML document will have the following DOCTYPE declaration:
335 <!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd">
337 The UTF-8 character encoding will be used.
339 This method is an exception to the general rule that the results of
340 concurrently executing multiple methods in this class yields results equivalent
341 to some serial execution. If the preferences at this node are modified
342 concurrently with an invocation of this method, the exported preferences
343 comprise a "fuzzy snapshot" of the preferences contained in the node; some of
344 the concurrent modifications may be reflected in the exported data while others
348 os - the output stream on which to emit the XML document.
350 *java.util.prefs.Preferences.exportSubtree(OutputStream)*
352 public abstract void exportSubtree(java.io.OutputStream os)
353 throws |java.util.prefs.BackingStoreException|
354 |java.io.IOException|
356 Emits an XML document representing all of the preferences contained in this
357 node and all of its descendants. This XML document is, in effect, an offline
358 backup of the subtree rooted at the node.
360 The XML document will have the following DOCTYPE declaration:
362 <!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd">
364 The UTF-8 character encoding will be used.
366 This method is an exception to the general rule that the results of
367 concurrently executing multiple methods in this class yields results equivalent
368 to some serial execution. If the preferences or nodes in the subtree rooted at
369 this node are modified concurrently with an invocation of this method, the
370 exported preferences comprise a "fuzzy snapshot" of the subtree; some of the
371 concurrent modifications may be reflected in the exported data while others may
375 os - the output stream on which to emit the XML document.
377 *java.util.prefs.Preferences.flush()*
379 public abstract void flush()
380 throws |java.util.prefs.BackingStoreException|
382 Forces any changes in the contents of this preference node and its descendants
383 to the persistent store. Once this method returns successfully, it is safe to
384 assume that all changes made in the subtree rooted at this node prior to the
385 method invocation have become permanent.
387 Implementations are free to flush changes into the persistent store at any
388 time. They do not need to wait for this method to be called.
390 When a flush occurs on a newly created node, it is made persistent, as are any
391 ancestors (and descendants) that have yet to be made persistent. Note however
392 that any preference value changes in ancestors are not guaranteed to be made
395 If this method is invoked on a node that has been removed with the
396 (|java.util.prefs.Preferences|) method, flushSpi() is invoked on this node, but
401 *java.util.prefs.Preferences.get(String,String)*
403 public abstract |java.lang.String| get(
404 java.lang.String key,
405 java.lang.String def)
407 Returns the value associated with the specified key in this preference node.
408 Returns the specified default if there is no value associated with the key, or
409 the backing store is inaccessible.
411 Some implementations may store default values in their backing stores. If there
412 is no value associated with the specified key but there is such a stored
413 default, it is returned in preference to the specified default.
416 key - key whose associated value is to be returned.
417 def - the value to be returned in the event that this preference node has no value
420 Returns: the value associated with key, or def if no value is associated with key, or
421 the backing store is inaccessible.
423 *java.util.prefs.Preferences.getBoolean(String,boolean)*
425 public abstract boolean getBoolean(
426 java.lang.String key,
429 Returns the boolean value represented by the string associated with the
430 specified key in this preference node. Valid strings are "true", which
431 represents true, and "false", which represents false. Case is ignored, so, for
432 example, "TRUE" and "False" are also valid. This method is intended for use in
433 conjunction with (|java.util.prefs.Preferences|) .
435 Returns the specified default if there is no value associated with the key, the
436 backing store is inaccessible, or if the associated value is something other
437 than "true" or "false", ignoring case.
439 If the implementation supports stored defaults and such a default exists and is
440 accessible, it is used in preference to the specified default, unless the
441 stored default is something other than "true" or "false", ignoring case, in
442 which case the specified default is used.
445 key - key whose associated value is to be returned as a boolean.
446 def - the value to be returned in the event that this preference node has no value
447 associated with key or the associated value cannot be interpreted as a
448 boolean, or the backing store is inaccessible.
450 Returns: the boolean value represented by the string associated with key in this
451 preference node, or def if the associated value does not exist or
452 cannot be interpreted as a boolean.
454 *java.util.prefs.Preferences.getByteArray(String,byte[])*
456 public abstract byte[] getByteArray(
457 java.lang.String key,
460 Returns the byte array value represented by the string associated with the
461 specified key in this preference node. Valid strings are Base64 encoded binary
462 data, as defined in RFC 2045, Section 6.8, with one minor change: the string
463 must consist solely of characters from the Base64 Alphabet; no newline
464 characters or extraneous characters are permitted. This method is intended for
465 use in conjunction with (|java.util.prefs.Preferences|) .
467 Returns the specified default if there is no value associated with the key, the
468 backing store is inaccessible, or if the associated value is not a valid Base64
469 encoded byte array (as defined above).
471 If the implementation supports stored defaults and such a default exists and is
472 accessible, it is used in preference to the specified default, unless the
473 stored default is not a valid Base64 encoded byte array (as defined above), in
474 which case the specified default is used.
477 key - key whose associated value is to be returned as a byte array.
478 def - the value to be returned in the event that this preference node has no value
479 associated with key or the associated value cannot be interpreted as a
480 byte array, or the backing store is inaccessible.
482 Returns: the byte array value represented by the string associated with key in this
483 preference node, or def if the associated value does not exist or
484 cannot be interpreted as a byte array.
486 *java.util.prefs.Preferences.getDouble(String,double)*
488 public abstract double getDouble(
489 java.lang.String key,
492 Returns the double value represented by the string associated with the
493 specified key in this preference node. The string is converted to an integer as
494 by (|java.lang.Double|) . Returns the specified default if there is no value
495 associated with the key, the backing store is inaccessible, or if
496 Double.parseDouble(String) would throw a (|java.lang.NumberFormatException|) if
497 the associated value were passed. This method is intended for use in
498 conjunction with (|java.util.prefs.Preferences|) .
500 If the implementation supports stored defaults and such a default exists, is
501 accessible, and could be converted to a double with Double.parseDouble, this
502 double is returned in preference to the specified default.
505 key - key whose associated value is to be returned as a double.
506 def - the value to be returned in the event that this preference node has no value
507 associated with key or the associated value cannot be interpreted as a
508 double, or the backing store is inaccessible.
510 Returns: the double value represented by the string associated with key in this
511 preference node, or def if the associated value does not exist or
512 cannot be interpreted as a double.
514 *java.util.prefs.Preferences.getFloat(String,float)*
516 public abstract float getFloat(
517 java.lang.String key,
520 Returns the float value represented by the string associated with the specified
521 key in this preference node. The string is converted to an integer as by
522 (|java.lang.Float|) . Returns the specified default if there is no value
523 associated with the key, the backing store is inaccessible, or if
524 Float.parseFloat(String) would throw a (|java.lang.NumberFormatException|) if
525 the associated value were passed. This method is intended for use in
526 conjunction with (|java.util.prefs.Preferences|) .
528 If the implementation supports stored defaults and such a default exists, is
529 accessible, and could be converted to a float with Float.parseFloat, this float
530 is returned in preference to the specified default.
533 key - key whose associated value is to be returned as a float.
534 def - the value to be returned in the event that this preference node has no value
535 associated with key or the associated value cannot be interpreted as a
536 float, or the backing store is inaccessible.
538 Returns: the float value represented by the string associated with key in this
539 preference node, or def if the associated value does not exist or
540 cannot be interpreted as a float.
542 *java.util.prefs.Preferences.getInt(String,int)*
544 public abstract int getInt(
545 java.lang.String key,
548 Returns the int value represented by the string associated with the specified
549 key in this preference node. The string is converted to an integer as by
550 (|java.lang.Integer|) . Returns the specified default if there is no value
551 associated with the key, the backing store is inaccessible, or if
552 Integer.parseInt(String) would throw a (|java.lang.NumberFormatException|) if
553 the associated value were passed. This method is intended for use in
554 conjunction with (|java.util.prefs.Preferences|) .
556 If the implementation supports stored defaults and such a default exists, is
557 accessible, and could be converted to an int with Integer.parseInt, this int is
558 returned in preference to the specified default.
561 key - key whose associated value is to be returned as an int.
562 def - the value to be returned in the event that this preference node has no value
563 associated with key or the associated value cannot be interpreted as an
564 int, or the backing store is inaccessible.
566 Returns: the int value represented by the string associated with key in this preference
567 node, or def if the associated value does not exist or cannot be
568 interpreted as an int.
570 *java.util.prefs.Preferences.getLong(String,long)*
572 public abstract long getLong(
573 java.lang.String key,
576 Returns the long value represented by the string associated with the specified
577 key in this preference node. The string is converted to a long as by
578 (|java.lang.Long|) . Returns the specified default if there is no value
579 associated with the key, the backing store is inaccessible, or if
580 Long.parseLong(String) would throw a (|java.lang.NumberFormatException|) if the
581 associated value were passed. This method is intended for use in conjunction
582 with (|java.util.prefs.Preferences|) .
584 If the implementation supports stored defaults and such a default exists, is
585 accessible, and could be converted to a long with Long.parseLong, this long is
586 returned in preference to the specified default.
589 key - key whose associated value is to be returned as a long.
590 def - the value to be returned in the event that this preference node has no value
591 associated with key or the associated value cannot be interpreted as a
592 long, or the backing store is inaccessible.
594 Returns: the long value represented by the string associated with key in this preference
595 node, or def if the associated value does not exist or cannot be
596 interpreted as a long.
598 *java.util.prefs.Preferences.importPreferences(InputStream)*
600 public static void importPreferences(java.io.InputStream is)
601 throws |java.util.prefs.InvalidPreferencesFormatException|
602 |java.io.IOException|
604 Imports all of the preferences represented by the XML document on the specified
605 input stream. The document may represent user preferences or system
606 preferences. If it represents user preferences, the preferences will be
607 imported into the calling user's preference tree (even if they originally came
608 from a different user's preference tree). If any of the preferences described
609 by the document inhabit preference nodes that do not exist, the nodes will be
612 The XML document must have the following DOCTYPE declaration:
614 <!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd">
616 (This method is designed for use in conjunction with
617 (|java.util.prefs.Preferences|) and (|java.util.prefs.Preferences|) .
619 This method is an exception to the general rule that the results of
620 concurrently executing multiple methods in this class yields results equivalent
621 to some serial execution. The method behaves as if implemented on top of the
622 other public methods in this class, notably (|java.util.prefs.Preferences|) and
623 (|java.util.prefs.Preferences|) .
626 is - the input stream from which to read the XML document.
628 *java.util.prefs.Preferences.isUserNode()*
630 public abstract boolean isUserNode()
632 Returns true if this preference node is in the user preference tree, false if
633 it's in the system preference tree.
637 Returns: true if this preference node is in the user preference tree, false if it's in
638 the system preference tree.
640 *java.util.prefs.Preferences.keys()*
642 public abstract |java.lang.String|[] keys()
643 throws |java.util.prefs.BackingStoreException|
645 Returns all of the keys that have an associated value in this preference node.
646 (The returned array will be of size zero if this node has no preferences.)
648 If the implementation supports stored defaults and there are any such defaults
649 at this node that have not been overridden, by explicit preferences, the
650 defaults are returned in the array in addition to any explicit preferences.
654 Returns: an array of the keys that have an associated value in this preference node.
656 *java.util.prefs.Preferences.name()*
658 public abstract |java.lang.String| name()
660 Returns this preference node's name, relative to its parent.
664 Returns: this preference node's name, relative to its parent.
666 *java.util.prefs.Preferences.node(String)*
668 public abstract |java.util.prefs.Preferences| node(java.lang.String pathName)
670 Returns the named preference node in the same tree as this node, creating it
671 and any of its ancestors if they do not already exist. Accepts a relative or
672 absolute path name. Relative path names (which do not begin with the slash
673 character ('/')) are interpreted relative to this preference node.
675 If the returned node did not exist prior to this call, this node and any
676 ancestors that were created by this call are not guaranteed to become permanent
677 until the flush method is called on the returned node (or one of its ancestors
681 pathName - the path name of the preference node to return.
683 Returns: the specified preference node.
685 *java.util.prefs.Preferences.nodeExists(String)*
687 public abstract boolean nodeExists(java.lang.String pathName)
688 throws |java.util.prefs.BackingStoreException|
690 Returns true if the named preference node exists in the same tree as this node.
691 Relative path names (which do not begin with the slash character ('/')) are
692 interpreted relative to this preference node.
694 If this node (or an ancestor) has already been removed with the
695 (|java.util.prefs.Preferences|) method, it is legal to invoke this method, but
696 only with the path name ""; the invocation will return false. Thus, the idiom
697 p.nodeExists("") may be used to test whether p has been removed.
700 pathName - the path name of the node whose existence is to be checked.
702 Returns: true if the specified node exists.
704 *java.util.prefs.Preferences.parent()*
706 public abstract |java.util.prefs.Preferences| parent()
708 Returns the parent of this preference node, or null if this is the root.
712 Returns: the parent of this preference node.
714 *java.util.prefs.Preferences.put(String,String)*
716 public abstract void put(
717 java.lang.String key,
718 java.lang.String value)
720 Associates the specified value with the specified key in this preference node.
723 key - key with which the specified value is to be associated.
724 value - value to be associated with the specified key.
726 *java.util.prefs.Preferences.putBoolean(String,boolean)*
728 public abstract void putBoolean(
729 java.lang.String key,
732 Associates a string representing the specified boolean value with the specified
733 key in this preference node. The associated string is "true" if the value is
734 true, and "false" if it is false. This method is intended for use in
735 conjunction with (|java.util.prefs.Preferences|) .
738 key - key with which the string form of value is to be associated.
739 value - value whose string form is to be associated with key.
741 *java.util.prefs.Preferences.putByteArray(String,byte[])*
743 public abstract void putByteArray(
744 java.lang.String key,
747 Associates a string representing the specified byte array with the specified
748 key in this preference node. The associated string is the Base64 encoding of
749 the byte array, as defined in RFC 2045, Section 6.8, with one minor change: the
750 string will consist solely of characters from the Base64 Alphabet; it will not
751 contain any newline characters. Note that the maximum length of the byte array
752 is limited to three quarters of MAX_VALUE_LENGTH so that the length of the
753 Base64 encoded String does not exceed MAX_VALUE_LENGTH. This method is intended
754 for use in conjunction with (|java.util.prefs.Preferences|) .
757 key - key with which the string form of value is to be associated.
758 value - value whose string form is to be associated with key.
760 *java.util.prefs.Preferences.putDouble(String,double)*
762 public abstract void putDouble(
763 java.lang.String key,
766 Associates a string representing the specified double value with the specified
767 key in this preference node. The associated string is the one that would be
768 returned if the double value were passed to (|java.lang.Double|) . This method
769 is intended for use in conjunction with (|java.util.prefs.Preferences|) .
772 key - key with which the string form of value is to be associated.
773 value - value whose string form is to be associated with key.
775 *java.util.prefs.Preferences.putFloat(String,float)*
777 public abstract void putFloat(
778 java.lang.String key,
781 Associates a string representing the specified float value with the specified
782 key in this preference node. The associated string is the one that would be
783 returned if the float value were passed to (|java.lang.Float|) . This method is
784 intended for use in conjunction with (|java.util.prefs.Preferences|) .
787 key - key with which the string form of value is to be associated.
788 value - value whose string form is to be associated with key.
790 *java.util.prefs.Preferences.putInt(String,int)*
792 public abstract void putInt(
793 java.lang.String key,
796 Associates a string representing the specified int value with the specified key
797 in this preference node. The associated string is the one that would be
798 returned if the int value were passed to (|java.lang.Integer|) . This method is
799 intended for use in conjunction with (|java.util.prefs.Preferences|) .
802 key - key with which the string form of value is to be associated.
803 value - value whose string form is to be associated with key.
805 *java.util.prefs.Preferences.putLong(String,long)*
807 public abstract void putLong(
808 java.lang.String key,
811 Associates a string representing the specified long value with the specified
812 key in this preference node. The associated string is the one that would be
813 returned if the long value were passed to (|java.lang.Long|) . This method is
814 intended for use in conjunction with (|java.util.prefs.Preferences|) .
817 key - key with which the string form of value is to be associated.
818 value - value whose string form is to be associated with key.
820 *java.util.prefs.Preferences.remove(String)*
822 public abstract void remove(java.lang.String key)
824 Removes the value associated with the specified key in this preference node, if
827 If this implementation supports stored defaults, and there is such a default
828 for the specified preference, the stored default will be "exposed" by this
829 call, in the sense that it will be returned by a succeeding call to get.
832 key - key whose mapping is to be removed from the preference node.
834 *java.util.prefs.Preferences.removeNode()*
836 public abstract void removeNode()
837 throws |java.util.prefs.BackingStoreException|
839 Removes this preference node and all of its descendants, invalidating any
840 preferences contained in the removed nodes. Once a node has been removed,
841 attempting any method other than (|java.util.prefs.Preferences|) ,
842 (|java.util.prefs.Preferences|) , (|java.util.prefs.Preferences|) ,
843 (|java.util.prefs.Preferences|) or
844 nodeExists("")(|java.util.prefs.Preferences|) on the corresponding Preferences
845 instance will fail with an IllegalStateException. (The methods defined on
846 (|java.lang.Object|) can still be invoked on a node after it has been removed;
847 they will not throw IllegalStateException.)
849 The removal is not guaranteed to be persistent until the flush method is called
850 on this node (or an ancestor).
852 If this implementation supports stored defaults, removing a node exposes any
853 stored defaults at or below this node. Thus, a subsequent call to nodeExists on
854 this node's path name may return true, and a subsequent call to node on this
855 path name may return a (different) Preferences instance representing a
856 non-empty collection of preferences and/or children.
860 *java.util.prefs.Preferences.removeNodeChangeListener(NodeChangeListener)*
862 public abstract void removeNodeChangeListener(java.util.prefs.NodeChangeListener ncl)
864 Removes the specified NodeChangeListener, so it no longer receives change
868 ncl - The NodeChangeListener to remove.
870 *java.util.prefs.Preferences.removePreferenceChangeListener(PreferenceChangeListener)*
872 public abstract void removePreferenceChangeListener(java.util.prefs.PreferenceChangeListener pcl)
874 Removes the specified preference change listener, so it no longer receives
875 preference change events.
878 pcl - The preference change listener to remove.
880 *java.util.prefs.Preferences.sync()*
882 public abstract void sync()
883 throws |java.util.prefs.BackingStoreException|
885 Ensures that future reads from this preference node and its descendants reflect
886 any changes that were committed to the persistent store (from any VM) prior to
887 the sync invocation. As a side-effect, forces any changes in the contents of
888 this preference node and its descendants to the persistent store, as if the
889 flush method had been invoked on this node.
893 *java.util.prefs.Preferences.systemNodeForPackage(Class<?>)*
895 public static |java.util.prefs.Preferences| systemNodeForPackage(java.lang.Class<?> c)
897 Returns the preference node from the system preference tree that is associated
898 (by convention) with the specified class's package. The convention is as
899 follows: the absolute path name of the node is the fully qualified package
900 name, preceded by a slash ('/'), and with each period ('.') replaced by a
901 slash. For example the absolute path name of the node associated with the class
902 com.acme.widget.Foo is /com/acme/widget.
904 This convention does not apply to the unnamed package, whose associated
905 preference node is <unnamed>. This node is not intended for long term use, but
906 for convenience in the early development of programs that do not yet belong to
907 a package, and for "throwaway" programs. Valuable data should not be stored at
908 this node as it is shared by all programs that use it.
910 A class Foo wishing to access preferences pertaining to its package can obtain
911 a preference node as follows:
913 static Preferences prefs = Preferences.systemNodeForPackage(Foo.class);
915 This idiom obviates the need for using a string to describe the preferences
916 node and decreases the likelihood of a run-time failure. (If the class name is
917 misspelled, it will typically result in a compile-time error.)
919 Invoking this method will result in the creation of the returned node and its
920 ancestors if they do not already exist. If the returned node did not exist
921 prior to this call, this node and any ancestors that were created by this call
922 are not guaranteed to become permanent until the flush method is called on the
923 returned node (or one of its ancestors or descendants).
926 c - the class for whose package a system preference node is desired.
928 Returns: the system preference node associated with the package of which c is a member.
930 *java.util.prefs.Preferences.systemRoot()*
932 public static |java.util.prefs.Preferences| systemRoot()
934 Returns the root preference node for the system.
938 Returns: the root preference node for the system.
940 *java.util.prefs.Preferences.toString()*
942 public abstract |java.lang.String| toString()
944 Returns a string representation of this preferences node, as if computed by the
945 expression:(this.isUserNode() ? "User" : "System") + " Preference Node: " +
950 *java.util.prefs.Preferences.userNodeForPackage(Class<?>)*
952 public static |java.util.prefs.Preferences| userNodeForPackage(java.lang.Class<?> c)
954 Returns the preference node from the calling user's preference tree that is
955 associated (by convention) with the specified class's package. The convention
956 is as follows: the absolute path name of the node is the fully qualified
957 package name, preceded by a slash ('/'), and with each period ('.') replaced by
958 a slash. For example the absolute path name of the node associated with the
959 class com.acme.widget.Foo is /com/acme/widget.
961 This convention does not apply to the unnamed package, whose associated
962 preference node is <unnamed>. This node is not intended for long term use, but
963 for convenience in the early development of programs that do not yet belong to
964 a package, and for "throwaway" programs. Valuable data should not be stored at
965 this node as it is shared by all programs that use it.
967 A class Foo wishing to access preferences pertaining to its package can obtain
968 a preference node as follows:
970 static Preferences prefs = Preferences.userNodeForPackage(Foo.class);
972 This idiom obviates the need for using a string to describe the preferences
973 node and decreases the likelihood of a run-time failure. (If the class name is
974 misspelled, it will typically result in a compile-time error.)
976 Invoking this method will result in the creation of the returned node and its
977 ancestors if they do not already exist. If the returned node did not exist
978 prior to this call, this node and any ancestors that were created by this call
979 are not guaranteed to become permanent until the flush method is called on the
980 returned node (or one of its ancestors or descendants).
983 c - the class for whose package a user preference node is desired.
985 Returns: the user preference node associated with the package of which c is a member.
987 *java.util.prefs.Preferences.userRoot()*
989 public static |java.util.prefs.Preferences| userRoot()
991 Returns the root preference node for the calling user.
995 Returns: the root preference node for the calling user.