Java Notes-12 (Preferences API, the Logging API)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.