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

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);

-Preferences are stored in two separate trees: system preferences and user preferences.System preferences are shared by all users of the Java installation. But user preferences

are 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 are 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");
prefs.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 room.");

-a logger for the name “global” is provided in the static field  Logger.global . You can use it as an 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 is sufficient to proceed. If the message doesn’t meet the required level, it is discarded at the source.

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  
时间: 2024-10-29 19:07:33

Java Notes-12(Preferences API, The Logging API)的相关文章

Java Logging API - Tutorial

Java Logging This article describes how to use the Logging API in Java programs. It includes an example for creating an HTML logger. Table of Contents 1. Overview 1.1. Logging 1.2. Logging in Java 1.3. Create a logger 1.4. Level 1.5. Handler 1.6. For

深入理解Java 8 Lambda(类库篇——Streams API,Collectors和并行)

转:http://zh.lucida.me/blog/java-8-lambdas-inside-out-library-features/ 关于 深入理解 Java 8 Lambda(语言篇--lambda,方法引用,目标类型和默认方法) 深入理解 Java 8 Lambda(类库篇--Streams API,Collector 和并行) 深入理解 Java 8 Lambda(原理篇--Java 编译器如何处理 lambda) 本文是深入理解 Java 8 Lambda 系列的第二篇,主要介绍

Java 8 新特性:Java 类库的新特性之日期时间API (Date/Time API ) ——诺诺"涂鸦"记忆

----------   诺诺学习技术交流博客.期待与您交流!    ---------- 详情请查看:http://blog.csdn.net/sun_promise  日期时间API (Date/Time API ) 1.Java8之前java.util.Date和Calendar类的弊端 1)最开始的时候,Date既要承载日期信息,又要做日期之间的转换,还要做不同日期格式的显示,职责较繁杂(不遵守单一职责). 后来从JDK 1.1 开始,这三项职责分开了: 使用Calendar类实现日期和

Atitit. 衡量项目规模 ----包含的类的数量 .net java类库包含多少类 多少个api方法??

Atitit. 衡量项目规模 ----包含的类的数量 .net java类库包含多少类 多少个api方法?? 1 framework 4.5 (10万个api)1 2 Jdk8   57M1 3 Gialen项目2 4 播放器项目 3500个类2 5 Jquery 1.11 (api 305个)2 6 Wordpress 4.2   (函数api详单(约500个api)2 7 Html5  860个api2 7.1 Css2 8 Js  430个3 1 framework 4.5 (10万个ap

spark2.x由浅入深深到底系列六之RDD java api调用scala api的原理

RDD java api其实底层是调用了scala的api来实现的,所以我们有必要对java api是怎么样去调用scala api,我们先自己简单的实现一个scala版本和java版本的RDD和SparkContext 一.简单实现scala版本的RDD和SparkContext class RDD[T](value: Seq[T]) {   //RDD的map操作   def map[U](f: T => U): RDD[U] = {     new RDD(value.map(f))   

[转]深入理解Java 8 Lambda(类库篇——Streams API,Collectors和并行)

以下内容转自: 作者:Lucida 微博:@peng_gong 豆瓣:@figure9 原文链接:http://zh.lucida.me/blog/java-8-lambdas-insideout-library-features 本文谢绝转载,如需转载需征得作者本人同意,谢谢. -------------------------------------内容分割线--------------------------------------------------------- 深入理解Java

五:用JAVA写一个阿里云VPC Open API调用程序

用JAVA写一个阿里云VPC Open API调用程序 摘要:用JAVA拼出来Open API的URL 引言 VPC提供了丰富的API接口,让网络工程是可以通过API调用的方式管理网络资源.用程序和软件管理自动化管理网络资源是一件显著提升运维效率和网络生产力的事情.产品经理教你写代码系列文章的目标是不懂代码的网络工程师能一步一步的学会用API管理网络. 另外通过文章标题大家也可以看出来,产品经理教你写代码肯定是一个业余班,里面的代码很多写的都不规范,可能也有很多Bug.专业选手可以参考的有限,请

使用Java程序消费SAP Leonardo的机器学习API

以sap leonardo作为关键字在微信上搜索,能搜到不少文章.但是我浏览了一下,好像没有发现有从具体编程角度上来介绍的.所以我就贡献一篇. 需求 开发一个Java程序,用户可以指定一张图片,该Java程序调用SAP Leonardo上训练好的机器学习API,该API会识别该图片,给用户返回一个文本信息,告诉用户识别结果. 访问https://api.sap.com, 点击API: SAP Leonardo Machine Learning - Functional Services 点击Pr

解决:ElasticSearch ClusterBlockException[blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];

简记 使用SkyWalking用ES做存储,发现运行一段时间会提示ElasticSearch ClusterBlockException[blocked by: [FORBIDDEN/12/index read-only / allow delete (api)]; 本以为是ES所在的系统出现磁盘满了的问题,简单查看发现还有10G左右空间,占用95%的磁盘,删除后已用磁盘空间降至40%,但问题依然存在, 尝试重启单节点的ES,使用Kibana连接时同样报出了上边的提示,所以怀疑不是SkyWalk