20145309 Java programming Eighth week of study summary

Source: Internet
Author: User
Tags locale

Log

java.util.logging Package provides a log function related classes and interfaces, the starting point for using the log is the logger class, the logger class's constructor is labeled protected, not java.util.logging the same package class cannot be created directly with new, do not use logger static Method.

logger and handler, by default, filter information by level, and if you do not make any changes, the parent LOGGER configuration of the LOGGER instance is the configuration of the Logger.global-logger-name space name LOGGER instance.

• In the absence of any configuration setting, the LOGGER instance that is obtained by default must be greater than or equal to the level.info of the Logger.global-logger-name namespace LOGGER instance setting to output information.

• When establishing a Filehandler specified pattern string, you can use "%h" to represent the user's root directory, or you can use "%t" to obtain the system staging directory, or use "%g" to automatically number the document.

· Handler is responsible for the output, formatter is responsible for formatting, and information filtering is referred to filter.

Internationalization Basics

The static Getbundle () method of ResourceBundle takes an instance of ResourceBundle, given the argument name is the main file name of the information document. Getbundle () will automatically find the corresponding. Properties document, and after getting the ResourceBundle instance, you can use the GetString () to specify the key to get.

Locale

• The three criteria for internationalization are the locale information, the resource bundle (Resource bundle), and the base name.

• The corresponding class for region information is locale, where you can specify the language encoding and locale code when setting up locale instances.

Stream related APIs

Stream is one of the important new features in JDK8. Files have several static methods, such as lines (), list (), walk (), and so on, for this kind of return stream instance of the API, mainly for the need of pipeline, lazy operation of the occasion.

• If you want to pipeline an array, one of the methods of the city is to use arrays's aslist () method to return to list, and then call the stream () method to get the stream instance, and another method is to use the arrays stream () method. It can return a stream instance after the array is specified.

Understanding NiO

NIO uses channels to connect data nodes, and when processing data, NIO allows you to set the buffer capacity, marking the chunks of interest in the buffer, such as the tag read location, the valid location of the data, and a clear () for these block markers, Advanced operations such as Rewind (), flip (), compact ().

using handler and formatter

1. The handler instance is responsible for the log output.

MemoryHandler不会格式化日志信息,信息会暂存于内存缓冲区,直到超过缓冲区大小,才将信息输出至指定的目标Handler。 StreamHandler可自行指定信息输出时使用的OutputStream实例,它与子类都会使用指定Formatter格式化信息。 ConsoleHandler创建时,会自动指定OutputStream为System.err,所以日志信息会显示在控制台。 FileHandler创建时会建立日志输出时使用的FileOutputStream,文档位置与名称可以使用模式Pattern字符串指定。SocketHandler创建时可以指定主机位置与端口,内部将自动建立网络联机,将日志信息传送至指定的主机。

2.Logger can use AddHandler () to add handler instances and remove handler using RemoveHandler ().

3. In the Create Filehandler, specify the pattern string:

使用“%h”来表示用户的根目录使用“%t”取得系统暂存目录 使用“%g”自动为文档编号使用“%h/config%g.log”表示将configN.log文件存储在用户根目录下,N表示每个信息的文档编号,会自动递增。

4.FileHandler default formatter is Xmlformatter; Consolehandler uses simpleformatter by default; These two classes are subclasses of formatter, The formatter can be set by Handler's Setformatter () method.

5. If you want to output information or store a document with a specific encoding, Handler has a setencoding () method to specify the text encoding.

customizing Handler, formatter, and filter

1. If the handler results provided in the Java.util.logging package do not meet the requirements, you can inherit the handler class, manipulate the abstract method publish (), flush (), and Close () methods to customize handler.

2. In the allocation of responsibilities, handler is responsible for the output, the format is referred to formatter, and information filtering is given to filter. Handler has a default isloggable () operation that filters information based on level and then filters the information using the specified filter. The format () method passes in the LogRecord and stores all the log information.

3. In addition to filtering by the hierarchy, additional filtering conditions can be added, and the filter interface can be manipulated.

using Logging.properties

Ways to change the configuration of a logger object:

(1)使用程序撰写方式 (2)通过logging.properties来设定Logger组态。
Stream related APIs

1. How to perform pipeline operations on an array:

(1)使用Arrays的asList()方法返回List,而后调用stream()方法取得Stream实例 (2)使用Arrays的stream()方法,可以指定数组后返回Stream实例。

New chars () and codepoints () are added to the 2.CharSequence to return Intstream, which represents the integer value of a string of characters, which represents the code point of a string of words Fu.

3.Math has also added a number of math-run-related APIs in JDK8, such as Multiplluexact (), Floormod (), Floordiv (), and so on.

Resources
    • Java Learning Notes (8th Edition)
    • Java Learning Note (8th Edition) Learning Guide

20145309 Java programming Eighth week of study summary

Related Article

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.