Summary:preferences API, the Logging API
-The Preferences API is like a portable version of the Windows registry, a mini-database in which you can keep small Amou NTS of information, accessible to all applications
-preferences is stored logically in a tree.
Preferences prefs = Preferences.userroot (). Node ("Oreilly/learningjava");p refs.put ("Author", "Niemeyer"); Prefs.putint ("edition", 4); String author = prefs.get ("Author", "Unknown"), int edition = Prefs.getint ("edition",-1);
-preferences is stored in and separate Trees:system Preferences and user Preferences. System preferences is shared by all users of the Java installation. But user preferences
is maintained separately for each user;
-the node () method accepts either a relative or an absolute path.
Preferences prefs =preferences.userroot (). Node ("oreilly"). Node ("Learningjava");
-often your application should be notified if changes is made to the preferences while it ' s running. You can get updates on preference changes using the Preferencechange
Listener and Nodechangelistener interfaces.
Preferences prefs =preferences.userroot (). Node ("/oreilly/learningjava");p Refs.addpreferencechangelistener (new Preferencechangelistener () {public void Preferencechange (Preferencechangeevent e) {System.out.println ("Value:" + E.getkey () + "changed to" + E.getnewvalue ());});
-the java.util.logging Package provides a highly flexible and easy-to-use logging framework for System Information, error messages, and fine-grained tracing (debugging) output.
-the heart of the logging framework is the logger, an instance of Java.util.logging.Logger.
Package Com.oreilly.learnjava;public class Book {static Logger log = Logger.getlogger ("Com.oreilly.learnjava.Book");
-the Logger provides a wide range of methods to log messages; Some take very detailed information, and some convenience methods take only a string for ease of use
Log.warning ("Disk 90% full."); Log.info ("New user joined chat.");
-A logger for the name "global" was provided in the static field Logger.global. You can use it as a alternative to the old standby System.out.println ()
Logger.global.info ("Doing foo ...")
-before a logger hands off a message to its handlers or its parent's handlers, it first checks whether the logging level I s sufficient to proceed. If the message doesn ' t meet the required level, it's discarded at the source.
| Level
meaning |
SEVERE |
Application failure |
Warnin |
Notification of potential problem |
INFO |
Messages of interest to end users |
CONFIG |
Detailed system configuration information for administrators |
FINE |
Successively more detailed application tracing information for developers |
Finer |
|
FINEST |
|
Java Notes-12 (Preferences API, the Logging API)