Datasheet

Retrieving Information about the Node
Each node has information associated with it, such as its path, parent and children nodes, and the node’s
name. The methods to manipulate this information are shown here.
Method Description
String absolutePath() This method returns the absolute path to the current node. The
absolute path starts at the root node,
/, and continues to the cur-
rent node.
String[] childrenNames() Returns an array of the names of all child nodes of the current
node.
boolean isUserNode() Returns true if this node is part of the user configuration tree, or
false if this node is part of the system configuration tree.
String name() Returns the name of the current node.
Preferences parent() Returns a Preferences reference to the parent of the current
node, or null if trying to get the parent of the root node.
Retrieving Preference Values from the Node
The following methods act much like those from the Hashtable class. The key difference is that there
are versions of the
get for most primitive types. Each type is associated with a specific key, a string
standing for the name of the configuration parameter.
Method Description
String[] keys() Returns an array of strings that contains the names of all keys in
the current preferences node.
String get(String key, Returns the string associated with a specified key. If the key does
String def) not exist, it is created with the default value def and this default
value is then returned.
boolean getBoolean Returns the boolean associated with a specified key. If the key
(String key, boolean does not exist, it is created with the default value def and this
def) default value is then returned.
byte[] getByteArray Returns the byte array associated with a specified key. If the key
(String key, byte[] def) does not exist, it is created with the default value def and this
default value is then returned.
double getDouble(String Returns the double associated with a specified key. If the key
key, double def) does not exist, it is created with the default value def and this
default value is then returned.
float getFloat(String Returns the float associated with a specified key. If the key does
key, float def) not exist, it is created with the default value def and this default
value is then returned.
72
Part I: Thinking Like a Java Developer
05_777106 ch01.qxp 11/28/06 10:43 PM Page 72