20145326 Java Programming 8th Week of study summary

Source: Internet
Author: User

20145326 "Java Program Design" The 8th Week study summary textbook Learning content Summary

14th Chapter

I. Knowledge of NIO

1.NIO Narration

For advanced input/output processing, Java provides the NIO (New IO) from JDK1.4, while Java SE7 provides NIO2 to recognize and utilize these advanced input/output processing APIs, which can be very useful for the processing efficiency of input/output. InputStream, OutputStream input/output, basically in bytes for low-level processing, although you have to face the byte array directly, but in fact, most of the byte array in the entire block processing. Although there are some decorations in the Java.io suite, these classes are not suitable if they are processed in bytes or chunks of interest in the string, they must compose their own APIs or find relevant link libraries to handle the details of indexes, tags, and so on. In contrast to stream input/output using InputStream, outputstream to connect data sources and destinations, 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, For these block tags, advanced operations such as clear (), rewind (), flip (), compact () are provided.

2.Channel Architecture and operations

The channel-related interfaces and classes in NiO, is located in the Java.nio.channels suite, the channel interface is the sub-interface of the autoclosable, so you can use the JDK7 after the attempt to close the resource syntax, the channel interface has a new IsOpen () method to confirm that the channel is open. Bytechannel does not define any method, simply inherits the behavior of Readablebytechannel and Writablebytechannel, Bytechannel sub-interface Seekablebytechannel can read and change the next location to access data.

3.Buffer Architecture and operations

In the NIO design, Data is processed in Java.nio.Buffer, buffer is an abstract class that defines the advanced operations on data chunks such as clear (), rewind (), flip (), compact (), which are all buffer and actually return this. The size of the buffer can be obtained with the capacity () method, and the data bounds index value of the buffer can be obtained with the limit () method, and the position index value of the next readable data of buffer can be obtained by the position () method. When a buffer has just been configured or called the Clear () method, limit () equals capacity (), and position () is 0.

When the Rewind () method is called, the position is set to 0, and the limit is constant, which is usually used when you want to read a piece of data in buffer repeatedly, acting as the position (0) method that calls buffer alone.

Ii.. NIO2 File System

1.nio2 Architecture

The NIO2 file System API provides a standard set of interfaces and classes that application developers can do with a file system based on these standard interfaces. Application developers primarily use Java.nio.file and Java.nio.file.attribute, an abstract class or interface that must be manipulated in a package that is operated by a file system provider. The center of the NIO2 file system is Java.nio.file.spi.FileSystemProvider, which itself is an abstract class. is the class that the file system provider operates. The function is to produce java.nio.file and Java.nio.file.attribute objects of various abstract classes or interfaces.

2. Operation Path

To get the path instance, you can use the Paths.get () method, the most basic way, is to use the string path, you can use the relative path and absolute path. The path instance represents only the path information, and the actual document or folder that corresponds to it does not necessarily exist.

Operation Result:

3. property reading and setting

In the past, there was no standard way to obtain different attributes supported by different file systems, and in JDK7, you could obtain supported attribute information for different file systems.

Operation Result:

Operation Result:

4. Operating Documents and directories

If you want to delete the document or directory that the path represents, You can use the Files.delete () method, which throws a nosuchfileexception if it does not exist, and throws a directorynotemptyexception if the document cannot be deleted because the directory is not empty. You can also delete a document using the Files.deleteifexists () method, which is called when the document does not exist and does not throw an exception. Files.copy () also has two overloaded versions, one that accepts InputStream as the source, can read the data directly, and copies the results to the specified path, and the other Files.copy () version is the copy of the source path to the specified outputstream. To move a document or directory, you can use the Files.move () method, similar to the Files.copy () method, to specify the source path, destination path, and copyoption.

5. Read and access the directory

If you want to obtain the file system root path information, you can use the FileSystem getrootdirectory () method.

Operation Result:

6. Filter, Search for documents

If you want to filter the documents that you want to display when you list the contents of the catalog, for example, you want to display only the. class and. Jar documents, you can specify a filter condition of * For the second parameter when using Files.newdirectorystream (). {Class,jar}. Another version of Files.newdirectorystream () accepts the Directorystream.filter interface operand, and if the GLOB syntax does not meet the conditional filtering requirements, you can manipulate the Directorystream.filter's accept () method from Define the filter criteria.

Operation Result:

15th Chapter

First, the log

1. Introduction to the Log API

The Java.util.logging package provides logging functionality related classes and interfaces. The benefit of using the standard Java platform is that you do not have to configure the log component in addition, the starting point for using the log is the logger class, and the constructor for the logger class is labeled protected. Classes that are not java.util.logging are not created directly with new, and to get logger instances, you must use Logger's static method GetLogger (). When you call GetLogger (), you must specify the namespace to which the logger instance belongs. Namespace with "." Differentiated as a hierarchy. Logger with the same namespace level, with the same parent logger configuration. The namespace is named as the class full name, usually in which class the logger is obtained. Simply put, logger is the starting point of recording information, to output the information, must first through the level and filter logger, and then through the level of handler filter, format information to formatter, The action of outputting information is actually handler responsible.

Operation Result:

2. Specify the log level

LOGGER and handler by default will first filter the information according to level, if not made any changes, the LOGGER instance of the parent LOGGER configuration, is Logger.globalLOGGER The name namespace logger the configuration of the instance, the configuration of this instance is set to info, the parent logger instance can be obtained through the getparent () of the logger instance, and a set level instance can be obtained by Getlevel (). The information processing of LOGGER will propagate to the parent LOGGER, that is to say, without any configuration setting, the LOGGER instance obtained by default must be greater than or equal to Logger.globalLOGGER The name namespace logger The level.info of the instance setting, it is possible to output information.

Operation Result:

3. Using handler and Formatter

Memoryhandler does not format the log information, the information is staged in the memory buffer until the buffer size is exceeded to output the information to the specified destination handler. Streamhandler can specify the OutputStream instance that is used when the information is output by itself, and the subclass uses the specified formatter formatting information, Consolehandler when it is created, OutputStream is automatically specified as System.err, so the log information is displayed on the console. Filehandler the FileOutputStream used when creating the log output when it is created, the document location and name can be specified using the pattern string.

4. Customizing handler, Formatter, 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 (), close () from the definition handler, and recommend that you consider the filtering and formatting of the information.

Operation Result:

5. Using Logging.properties

It is very convenient to change the configuration of the Logger object by using the method of writing the program, in fact, the logger configuration can be set by Logging.properties.

Ii. the basis of internationalization

1. Using ResourceBundle

The static Getbundle () method of ResourceBundle takes a ResourceBundle instance, the given argument name is the main file name of the information document, and Getbundle () automatically finds the corresponding. Properties document.

2. Use locale

Three important concepts of internationalization: region information, resource bundle and base name.

Third, the rule expression

1. Introduction to Rule expressions

The rule expression is mainly used in character, string format comparison, and later in the field of information widely used. The rule representation basically consists of two characters: literal meaning word and metacharacters character.

Operation Result:

The following example uses String ReplaceAll () to demonstrate the difference between the 3 quantifiers.

Operation Result:

The following are examples of boundary comparisons:

Operation Result:

Operation Result:

2.Pattern and Matcher

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, so you cannot create the pattern instance with new and must be obtained through the static method compile () of the pattern.

Operation Result:

The following example allows you to enter a rule expression with the string you want to compare:

Operation Result:

Iv. JDK8 API Enhancements

1.StringJoiner, arrays new API

If you have a set of strings that you want to specify as a comma-delimited link between each string, the string adds a join () static method that can be used directly, not only the list, this version of join () can actually accept the iterable operand. The Paralleprefix (), Parallesetall (), and Parallesort () methods are added to the arrays.

2.Stream related APIs

If you want to pipe an array, one method is to use arrays's aslist () method to return to the list, and then call the stream () method to get the stream instance. Another way is to use the arrays stream () method, which can specify an array after the stream instance is returned.

Problems in teaching materials learning and the solving process

Lou said this week the task is to focus on learning 15 chapters, 14 chapters if no time can not look. Most of the students first reaction is "definitely no time". In fact, I feel good, I just follow their own pace, did not expect a smooth 14 chapters and 15 chapters of the content are learned (but the focus is placed in 15 chapters). Before Lou teacher said that the core content of Java is encapsulation, inheritance, polymorphism that part of the knowledge, indeed more abstract difficult to understand. After the content is to introduce the application of various APIs, are living examples, more specific, if it is difficult because of this part of the knowledge is unfamiliar, not familiar. Oneself first clear the clue, do not understand the basic knowledge to read a few times the book, and then more knock several times the code, carefully thinking summary, the code and knowledge points combined, feel immediately come up! Should pay attention to the scientific study method ~ do not blindly!!!

git hosting:

Managed:

Number of code statistics lines:

Other (sentiment, thinking, etc., optional)

Although I this week is self-taught two chapters, more knowledge points, but fortunately, nothing difficult, like Lou teacher said before, Java's core knowledge and difficulties have been learned, the following chapters are all introduced some of the application of the class. Look at the first time the textbook must feel strange, difficult to accept. It's a process, it's normal. In the continuous learning, I also constantly looking for their own good learning methods. Look at the first time the textbook has a general understanding of the mind sketched out a contour. And then see the second time is gradually understanding and experience, to the outline of the content, then can not only read, but also to combine the code on the book, I also have to take the initiative to tap the Code, the initiative to find the problem. The third time is to comb the knowledge point is also a memory, the brain and knowledge fusion. This way down to the knowledge will definitely have further control! There will be a qualitative leap in itself! To learn to grasp the focus, the strength of the blade, to find fun, maintain passion, improve learning efficiency! Now I am with the purpose to read the textbook, not as blind as before. I later found this particularly important! I know that the 14th and 15th chapters are the same as before, or introduce some kind of application, so I take the same approach as before, while reading, while summing up, reading a total of how many APIs, each API architecture is what, each API's role and considerations is what. In this way there is a systematic study, the sense of efficiency is very high! And the mind is clear. In fact, this knowledge is not difficult, we just feel strange. Students have fear mood and weariness, of course not to go in, but also talk about what efficiency! The knowledge of these two chapters is not as abstract and difficult to understand as the previous objects, encapsulation, inheritance, polymorphism, and so on, which are living concrete examples, which are actually very fast to accept. Lou teacher said is very right, the important thing is not to learn how much Java knowledge, but through continuous learning process, to summarize a set of suitable for their own good learning methods, which will be useful for a lifetime. Of course, different people are certain that the situation is not the same, suitable for their own is the best. My biggest harvest this week is to learn to use Git managed code, with the WC Statistics code line number, and really realize that learning also to speak science, not blind. Time is used much, not necessarily to learn well. Find your own learning methods to improve efficiency! This is more important than everything! Adjust your own mentality, any thing do not have fear mood, everything beginning difficult, as long as is right, insist! Will certainly benefit from the end!! I found out that git was not as difficult as we had imagined when I Zhou Zhengyi my classmates to show me the use of git over and over again. In fact, it is very simple, logic is very clear, I practice a few times to get started. Later on new things do not reject, do not bother, to accept it, and then through constant practice, finally master and use it!

Learning progress Bar
Lines of code (new/cumulative) Blog volume (Add/accumulate) Learning time (new/cumulative) Important growth
Goal 3500 rows 20 articles 300 hours
First week 120/120 1/1 14/14
Second week 340/460 1/2 14/28
Third week 200/660 1/3 14/42
Week Four 320/980 1/4 14/56
Week Five 280/1260 1/5 14/70
Week Six 478/1738 2/7 16/86
Seventh Week 425/2163 2/9 16/102
Eighth Week 859/3022 2/11 16/118 Learned to use the Git managed code, learned to use the WC statistics code line number

20145326 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.