20145207 Java Programming 8th Week of study summary

Source: Internet
Author: User
Tags configuration settings

Summary of learning contents of textbooks :

First, NIO and the NIO2

1.NIO the definition

The input and output of InputStream, OutputStream, is basically in bytes for low-level processing, although the need to directly face the array, but in fact, most of the byte array in the entire block processing. The dump () method is that the whole chunk of data is read in and then the whole piece of data is written out.

2.nio2 the definition

Nowadays, there are a variety of file systems in the world, and different file systems provide different access methods, file attributes, permission control and so on. Before the advent of JDK7, it was often necessary to write specific programs for specific files, not only in the form of no standards, but also in applications written for specific functions that would add to the burden on the application developer. The NIO2 file System API provides a set of standard class interfaces and classes that the file system provider is responsible for as long as the application developer is working on file systems based on these standard interfaces with the class, and how the underlying file system is actually performed.

Second, the general API

1. log API

    • 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, will be allowed to use logger static party such as: Logger Logger = Logger.getlogger ("Cc.openhome.Main").
    • The way to get Logger: Logger Logger = Logger.getlogger ("Main.class.getName").
    • Logger with the same namespace level, the parent logger will have the same configuration, and each logger will propagate to the parent logger after processing its own log action, allowing the parent logger to process the log.

2. Specify the log level

    • The parent LOGGER configuration of the LOGGER instance that is obtained is the Logger.global_logger_name namespace LOGGER instance, which can be getparent () to get the set LOGGER instance through Getlevel () Gets the set level instance.
    • LOGGER information processing will be transmitted to the parent LOGGER, without any configuration settings, the default LOGGER instance, the hierarchy must be greater than or equal to Logger.global_logger_ The name namespace logger The lever.info of the instance setting, it is possible to output information.
    • The level instance can be set by Setlevel (), and if log () specifies a lever instance that contains an int value that is less than the int value contained in the level instance set by logger, level does not log the information.
    • After logger filtering, you have to go through handler filtering, a logger can have more than one handler, can be Logger addhandler () add handler instance. In fact, when the information output, the current logger handler processing, will also be propagated to the parent logger all handler processing, the Gethandlers () method can be obtained by the current handler instance array. The 474 example in the book:
    • Without any configuration setting, the LOGGER instance obtained will only use the handler of the Logger.global_logger_name namespace LOGGER instance, and the default is to use Consolehandler, which is a subclass of handler , the function is to output the log information under the console, the default level is Level.info.

3. using Handler and Formatter

    • Memoryhandler does not format the log information, the information is staged in the memory buffer until it exceeds the size to output the information to the specified destination handler.
    • Streamhandler can specify the OutputStream instance that is used when the information is output, and it will use the specified formatter formatting information with the child class.
    • When Consolehandler is created, OutputStream is automatically specified as System.err, so the log information is displayed in the console.
    • Filehandler is created when the log output is established using the FileOutputStream, the document location and name can be specified using a pattern string.
    • Sockethandler can specify the host location and port when it is created, the internal network is automatically established, and the log information is transferred to the specified host.
    • Logger can use AddHandler () to add handler instances and remove handler using RemoveHandler ().
    • 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.

4.Pattern with the Matcher

    • In the program to use the expression, you must first for the rule representation of the analysis, validation, and so on, to determine the rules of expression syntax error, the string is compared.
    • The Java.util.regex.Pattern instance is the representative object of the rule representation in the JVM, and the pattern's constructor is marked as private and must be obtained through the static method compile () of the pattern.
    • After you have obtained an instance of pattern, you can use the split () method to cut the specified string by a regular representation, which is equal to the split () method using String.

5. customizing Handler,Formatter , and Filter

    • 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 the Close () method to customize the handler, It is recommended to consider the filtering and formatting of information.
    • Handler is responsible for output, formatted by formatter, and information filtering is handed to filter.
    • Custom formatter, which can inherit formatter after the operation of the abstract method format (), this method will pass in LogRecord, storing all the log information.

JDK8 API Enhanced Features

Stringjoiner , Arrays New API

1.string,join () , Stringjoiner

    • The new join () static method of string allows you to specify a comma-delimited connection between each string.

2.Arrays

    • Added Parallelprefix (), Parallelsetall (), and Parallelsort () methods on arrays.
    • The Parallelprefix () method allows you to specify a Xxxbinaryoperator instance to perform a stream-like reduce () procedure.
    • The Parallelsetall () method, which is used to initialize the array or to completely reset each index element.
    • The Parallelsort () method allows you to divide the specified array into sub-arrays and sort them in parallel, and then merge the sort.

Stream related API

1.Files has lines (), list (), walk () and other methods.

Rule expressions

    • literal meaning characters are characters that are compared by literal means.
    • Metacharacters characters that have different meanings in different contexts when not in the literal comparison.
    • The Java.util.regex.Pattern instance is the representative object of the regular expression in the JVM, and the pattern's constructor is marked as private, which is obtained through the static method compile () of the pattern. Another version of the Pattern.compole () method, you can specify a flag.
    • After you get the pattern instance, you can use the method: Split () Method: Cut the specified string by the regular expression Matcher () method: Specifies the string to compare Find () method: see if there is a string that matches the next Lookingat () : See if the string starts with the rule expression Group (): You can return a string that matches.
    • After you have obtained the Matcher instance, you can use the method: ReplaceAll () to replace the part of the rule expression with the specified string instead of Replacefirst () instead of the portion of the first composite Rule expression replaceend () instead of the part that finally conforms to the rule expression The start () method can obtain an index that conforms to the initial index of the string after the end () method can take the last character of the string

Problems in teaching materials learning and the solving process

Handler can set the information through Setlevel (), the following information is not only to set the logger hierarchy to Level.info, but also to set the level of handler. INFO.

In 474, the code mentions the contents of the 12 lambda, and after JDK8, several of the methods mentioned here are overloaded and can accept supplier instances.

Problems in code debugging and the resolution process

No, nothing.

20145207 Java Programming 8th Week of study summary

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.