Java Sixth Week Study summary

Source: Internet
Author: User

Study number 20145336 "Java program design" Fifth week study summary textbook Learning content Summary

Tenth chapter input and output

InputStream and OutputStream

  • Java abstracts the input/output into streams, the source and destination of the data, and the stream object that connects the two. From a procedural point of view, if you take the data out of the source, you can use the input stream, and if you write the data to the destination, you can use the output stream. In Java, the input stream object is an Java.io.InputStream instance, and the output stream object is an Java.io.OutputStream instance. Stream is an abstraction of "input output", and note that "input and output" is relative to the program.

  • Read and write: Each time the data is read from InputStream, it is first implanted into a byte array. The read () method of Inputsream attempts to read the data of a byte array length and returns the actual bytes read in, as long as it is not-1, which represents reading to the data. Has Penny uses the Write () method of OutputStream to specify the byte array to write out, the index of the incident, and the length of the data.

  • Standard input and output: System.in and System.out represent standard inputs and standard outputs, respectively. You can use the system's Setin () method to specify the InputStream instance and re-establish the standard input source. The standard output can be redirected to the document as long as the execution program is using > to direct the output to the specified document. If the Hello class executes System.out.println ("HelloWorld"): >java hello>hello.txt system.in: standard input, default association to keyboard (terminal input) System.out: Standard output, default associated to display (terminal output) System.err: standard error, default associated to display (terminal output) Input output redirection: Setin,setout,seterr

  • Adorner class: InputStream, OutStream provides streaming basic operations, and if you want to do processing for input/output data, you can use a wrapper class. The commonly used packager has the function of buffer bufferedoutputstream, Bufferedinputstream, with data conversion processing DataInputStream, DataOutputStream, ObjectInputStream, ObjectOutputStream, etc. with the ability to serialize objects. (1) Bufferedinputstream and Bufferedoutputstream Bufferedinputstream and Bufferedoutputstream mainly provide buffer function inside, operation and InputStream, OutputStream is not much different. (2) DataInputStream and DataOutputStream DataInputStream, DataOutputStream used to decorate InputStream, Outputstream,datainputstream, DataOutputStream, which provides methods for reading and writing Java basic data types, such as reading and writing int, double, boolean, and so on. (3) ObjectInputStream and ObjectOutputStream ObjectInputStream provide the ReadObject () method to read the data into the object, The ObjectOutputStream provides the WriteObject () method to write the object to the destination. Objects that can be processed by these two methods must operate the Java.io.Serializable interface, which does not define any method, but is used as an indication that the object can be serialized.

Chapter 11th threading and parallel APIs

    • Threads: The various examples that have been introduced so far are single-threaded programs, that is, a program that starts from the main () program entry point to the end with only one process. Sometimes you need a design program that can have multiple programs, called multithreaded programs. To allow the current process to pause time, you can use the static sleep () method of Java.lang.Thread, the specified unit is milliseconds, and calling this method must handle java.lang.InterruptedException. If you want to design the process independently of main (), you can compose the Java.lang.Runnable interface, and the entry point of the process is the operation run () method. The process starting from main () is executed by the main program, and you can create a thread instance to execute the Rin () method defined by the Runnable instance, and to start the thread execution of the specified thread, you must call the start () method of the thread instance. If an additional thread is started in the main thread, the default is to wait for all threads that are started to execute the run () method before terminating the JVM, and if a thread is marked as a daemon thread, the JVM terminates when all non-daemon threads end. Each thread belongs to a line Cheng group, and if it is not specified, it is classified into the line Cheng group that produces the child thread, or you can specify the line Cheng group yourself, and the thread cannot be replaced once it has been grouped into a group. Some methods of Threadgroup can make a difference to all threads in a group. If you want to get all the threads in the group at once, you can use the enumerate () method. The Activecount () method gets the number of threads for the group.

    • Parallel API: Using thread to build multithreaded programs, you must personally handle synchornized, Object locking, Wait (), notify (), Notifyall () and other details, if you need a thread pool, read and write to unlock high-level operations, Java.util.concurrent is provided after JDK5 to build a more robust parallel application based on the API. Parallel APIs can be categorized into the following classes: 1.Lock, Readwriter, and condition. 2. Use executor. 3. Introduction to Parallel collection

Problems in code debugging and the resolution process

This week's code hosting:

Learning progress bar Learning progress bar /Cumulative) new/cumulative)
lines of code (newBlog volume (Learning time (new/cumulative) Important growth
Goal 5000 rows 30 Articles 400 hours
First week 150/150 1/1 15/15
Second week 150/400 1/2 15/30
Third week 150/550 1/3 20/50
Week Four 150/700 1/4 16/56
Week Five 150/850 1/5 19/65
Week Six 150/1000 2/7 23/88
    • Java Learning Notes (8th Edition)
    • Java Learning Note (8th Edition) Learning Guide
    • ...

Java Sixth Week 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.