20145301 Java programming Eighth week of study summary

Source: Internet
Author: User
Tags locale

20145301 "Java Program design" Eighth Week study summary textbook Learning content Summary 15th part-General API Common API
  • LOG: Log information security is significant, audit, forensics, intrusion detection, etc. will use the log message
    • Logger 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 Logger with the same namespace hierarchy, the parent logger will be the same, and each logger will propagate to the parent logger after processing its own log action, allowing the parent logger to process the log.
    • Specifies the log level if no modifications have been made to the logger instance of the parent logger configuration, Is the configuration of the LOGGER instance of the Logger.global-logger-name space name, and in the absence of any configuration setting, the LOGGER instance obtained by default must be greater than or equal to the Logger.global-logger-name namespace LOGGER instance setting l Evel.info, it is possible to output information, and you can specify a level instance by Setlevel ().
  • Log API
    • Logger: Note You cannot use construction methods to generate Logger objects. 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 Law, such as:Logger logger = Logger.getLogger("xxx");
    • GetLogger: When calling GetLogger (), you must specify the namespace to which the logger instance belongs, with the namespace "." As a hierarchical distinction, the logger of the same namespace level, whose parent logger is configured identically. The namespace is named as the class full name, usually in which class the logger is obtained.
  • Specify the log level
    • Getlevel:
      • The parent logger configuration of the logger instance obtained is the logger instance of the namespace, which can be obtained by acquiring the set instance of the level Logger.GLOBAL_LOGGER_NAME getParent() logger getLevel() .
    • SetLevel: You can setLevel() set the level instance, and if log () specifies that the lever instance 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.

    • Handler: Output Media
      • Memoryhandler: The log information is not formatted and the information is staged in the memory buffer until the buffer size is exceeded to output the information to the specified destination handler.
      • Streamhandler: You can specify the OutputStream instance that is used when the information is output, and it will use the specified formatter formatting information with subclasses.
        • Consolehandler: When created, OutputStream is automatically specified as System.err, so the log information is displayed in the console.
        • Filehandler: The fileoutputstream that is used when creating the log output when it is created, and the document location and name can be specified using pattern string strings.
        • Sockethandler: The host location and port can be specified at creation time, and the internal network will be automatically established to transfer log information to the specified host.
    • Formatter: Formatting
      • Filehandler The default formatter is XMLFormatter ;
      • Consolehandler is used by default SimpleFormatter , these two classes are subclasses of formatter and can be setFormatter() set formatter by handler method.

    • Filter: Filtering

Internationalization Basics
    • Localization localization; internationalization (i18n) internationalization
    • ResourceBundle
      • 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 () The corresponding. Properties document is automatically found and can be obtained using the GetString () specified key after the ResourceBundle instance has been obtained.
    • Locale
      • The three criteria for internationalization are region (Locale) information, resource bundle (Resource bundle) and base name.
      • The area information represents a specific geographic, political, or cultural area, which is specified by a language code (represented by two lowercase letters) and an optional region code (denoted by two uppercase letters). The corresponding class of region information is locale, such as Locale locale=new Locale("zh","TW"); .
      • The resource bundle includes information about a specific region.
      • Each resource bundle that represents the same set of information but different regions share the same base name.
Regular expressions
  • Introduction to Regular expressions
    • Characters and metacharacters: letters and numbers are compared by literal means in regular expressions, and some characters are preceded by \ and are treated as meta-characters.
    • Character class: In a rule expression, multiple characters can be grouped together and become a character class. One way to categorize characters is to descriptors the word in [].
    • Greedy, non-greedy, exclusive quantifier: {n} is a kind of greedy quantifier notation, indicating that the preceding item appears n times. After the greedy quantifier notation is added? , it will become a step-by quantifier (lazy quantifier, non-greedy quantifier)

    • Boundary comparison

    • Post-Improvement Code

      PublicClass SplitDemo2 {Public static < Span class= "Hljs-keyword" >void main (string[] args) {< Span class= "Hljs-keyword" >for (String str:  "Justin dog Monica doggie Irene" . split ( "\ \bdog\\< Span class= "hljs-string" >b ")) {System.println (Str.trim ())}}}           
    • Operation Result:

    • Grouping and referencing: You can use () to group rule representations, in addition to being a sub-rule representation, with quantifiers.
  • Pattern/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.
    • As the textbook P492 example Regex.java the results of the operation:

JDK8 API Enhancements
    • JDK8, String adds a join () static method that can be used directly
      String message = String.join("-","Java","is","cool");will produce "Java-is-cool"
    • In JDK8, a number of methods have been added to arrays for parallelism of large arrays.
      parallelPrefix()方法You can specify a Xxxbinaryoperator instance to perform a stream-like reduce () method.
      parallelSetAll()方法Used to initialize an array or to completely reset each index element.
      parallelSort()方法You can divide the specified array into sub-arrays and sort them separately at the time of parallelism.
# # Other (sentiment, thinking, etc., optional)
      • "Attached 1" hosting:

      • "Attached 2" with Cloc.exe statistics code is as follows:

20145301 Java programming Eighth 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.