20145319 "Java program design" The sixth Week study summary textbook Learning content Summary
The tenth to tenth chapter of this week's learning material focuses on streaming, character processing and threading, and parallel APIs
1. Input and output
Streaming: Data in 1Java with source (source) and destination (destination), which is the streaming object 2 stream design: When you do not know the limited data source and destination, You can also rely on abstract inputstream and OutStream to write a dump () method for later use of 3InputStream and OutputStream: in Java, The input stream represents the object as an Java.io.InputStream instance, and the output stream represents the object as Java.io.OutputStream
The inheritance structure of the stream:
- Standard inputs and outputs: System.in and System.out are examples of inputstream and outstream, whereas system.in often rarely directly manipulate inputstream-related methods and can instead use Setin () To specify a InputStream instance, such as System.setin (new FileInputStream (args [0]))
- FileInputStream and Fileoutputstream:fileinputstream are subclasses of InputStream and can be used to read data as soon as the document is created. FileOutputStream is a OutStream instance that can be written out once created and closed with close () when not in use
- Bytearrayinputstream and Bytearrayoutputstream can specify a byte array to create an instance, and a byte array to read as a data source after creation
- All of the above keywords are actually manipulating the read () and write () abstract methods in InputStream and OutStream
3. Stream Processing Adorner:
- Definition: InputStream and OutputStream provide only the basic operation of the stream, and when you want to process the data, you use the Packager class, such as the scanner, the adorner is that the data are processed, such as buffering, serialization, data loading and so on
- bufferinputstream and bufferoutputstream: Data is read as much as possible into the memory buffer, reducing the number of times the data is read directly from the source, resulting in increased efficiency (faster access to memory)
- datainputstream and DataOutputStream: Provides methods for reading and writing Java primitives, which are automatically converted in the specified type and byte
2. Threads
Before the various instances of learning are single-threaded, that is, the program from main () into only one process, but at design time can be as many processes as necessary, is multithreaded (multi-thread) program
- Thread and runable:
- The JVM is a virtual machine, only the main thread of the CPU, if you want to increase the CPU to create a thread instance, the CPU execution of the entry point, defined in the runnable run () method
- Writing multithreaded programs can manipulate the Runnable interface or inherit the thread class, redefining the Run () method, but manipulating the Runnable interface makes the program more resilient
2. Thread Life cycle
- Daemon thread: At the end of all non-daemon threads, the JVM automatically terminates
- Basic state Diagram:start->runnable-> (blocked)->running->dead, Thread.Sleep (), wait () blocking, input and output completion, etc. will let the thread into the blocked state, When a thread enters the blocked, it is best to let another line into the running state, to avoid the CPU idle, is one of the ways to improve performance.
- Join (): Inserts a thread, insert B When a executes, wait for B to complete after a (can refer to join () time, such as join (1000) that is the join thread up to 1000 milliseconds to execute)
3. Wait and notice
- Wait (): Specify Waiting Schedule
- Notify (): Notify join Schedule
- Notifyall (): Lock competition, notify all waiting threads to participate in scheduling
4. Parallel API
- Lock, Readwritelock, and condition: Provides functions like synchronized, wait (), notify (), Notifyall (), and more advanced features
- The Executor:executor interface can separate the designation of the runnable from the actual execution
- The future is used in conjunction with callable
Problems in teaching materials learning and the solving process
CHAPTER10:AC BD AC BD A BC BD BD D ABD
CHAPTER11:A C B ab AB D b A b CD
Problems in code debugging and the resolution process
Recently in the back of the study of new content to write the first few chapters of the post-class operation, I thought it would be more relaxed, but the operation is not as simple as expected.
Code (HANOI):
This program doesn't seem to be a problem, but there are some issues
First of all, we need to understand what the problem is the program, Java.lang.StackOverflowError actually said that the program has a stack overflow, so that the program does not work properly
What is Stack overflow? What will cause the stack to overflow?
We all know that the buffer data must not be larger than the buffer size, and the stack overflow means that the data is large enough to overflow the buffer range.
There are generally two cases of stack overflow, one is the variable volume is too large, for example, when writing a program to define the variable int abc[]=new int[2*1024*1024]
The second is the problem with the program: the function call hierarchy is too deep, each call, function parameters, local variables and other information on the stack
When the move function loops itself, num--;......move (mid, from, to, Num-1), where the function is also used num-1 causes the function to loop and modify it into move (mid, from, To,num).
Hanoi running successfully
Other (sentiment, thinking, etc., optional)
- In the back to look at the previous operation, found a lot of operational problems of the idea of data structure and algorithm textbooks have, feel first understand the algorithm re-programming effect will be much better
Learning progress Bar
|
Lines of code (new/cumulative) |
Blog volume (Add/accumulate) |
Learning time (new/cumulative) |
Important growth |
Goal |
3500 rows |
28 Articles |
300 hours |
|
Week Five |
200/1200 |
1/5 |
20/105 |
|
Week Six |
300/1500 |
2/7 |
25/130 |
|
Seventh Week |
|
|
|
|
Eighth Week |
|
|
|
|
Resources
- Java Learning Notes (8th Edition)
- Java Learning Note (8th Edition) Learning Guide
- ...
20145319 Six weeks Study summary