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 amounts of information, accessible to all applications
-Preferences are stored logically in a tree.
Preferences prefs = Preferences.userRoot().node("oreilly/learningjava"); prefs.put("author", "Niemeyer"); prefs.putInt("edition", 4); String author = prefs.get("author", "unknown"); int edition = prefs.getInt("edition", -1);
-The node() method accepts either a relative or an absolute path.
Preferences prefs = Preferences.userRoot().node("oreilly").node("learningjava");
Preferences prefs = Preferences.userRoot().node("/oreilly/learningjava"); prefs.addPreferenceChangeListener( new PreferenceChangeListener() { public void preferenceChange(PreferenceChangeEvent e) { System.out.println("Value: " + e.getKey() + " changed to "+ e.getNewValue() ); } } );
-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");
log.warning("Disk 90% full."); log.info("New user joined chat room.");
Logger.global.info("Doing foo...")
Level | Meaning |
---|---|
SEVERE | Application failure |
WARNIN | Notification of potential problem |
INFO | Messages of general 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)
原文地址:http://blog.csdn.net/yu444/article/details/45601837