20145234 Huangfei "Java Programming" Sixth Week study summary

Source: Internet
Author: User

Summary of learning contents of teaching materials tenth. Input/output
      • Read and write files
      • The basis of network upload data
      • Parent class

InputStream and OutputStream

  • Stream is an abstraction of "input output", noting that "input and output" is relative to the program
  • InputStream and OutputStream
  • 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.
    • Read
    • For reading of character data, Java SE provides the Java.io.Reader class, which abstracts the source of character data read-in. The Java.io.Writer class is provided for writing to character data. It abstracts the destination that the data writes out.
    • Write
    • FileReader, FileWriter can read and write to the document, read or write by default using the operating system default encoding to do character conversion. When you start the JVM, you can specify-dfile.encoding to specify the encoding used by the FileReader, FileWriter.
    • binary files
  • Standard input and output
    • 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 and output redirection: Setin,setout,seterr
  • FileInputStream and FileOutputStream
  • FileInputStream is a subclass of InputStream, you can specify a file name to create an instance, once the document is created, and then it can be used to read data. FileOutputStream is a subclass of OutputStream, you can specify a file name to create an instance, once the document is created, and then it can be used to write data. Use Close () to close the document when not in use, whether FileInputStream or FileOutputStream.
    • File read/write
  • Adorner class
    • Decorator mode
    • Bufferedinputstream and Bufferedoutputstream: internal cushioning for increased efficiency
    • DataInputStream and DataOutputStream: Basic data type and byte conversion, API well, look at it.
    • ObjectInputStream and ObjectOutputStream
      • Java.io.Serializable interface

Character Processing classes

    1. Reader Writer: Abstracts the destination that the data reads into and writes out, and the data that is read into the char array is inserted.
    2. Character processing adorners: You can use Bufferreader and bufferwriter to buffer data and increase read and write efficiency.
Chapter 11th threading and parallel APIs

Thread

    1. Multiple threads can be implemented by creating a thread instance to execute the > Run method defined by the runnable instance.
    2. Inheriting the thread class can also be done with multiple processes, but without the elasticity of the runnable, using lambda expressions can also simplify the program.
    3. Thread life cycle: Daemon: At the end of all non-Daemon threads, the JVM automatically terminates
    4. Threadgroup: Used to manage threads in a group, enumerate can get all the threads in the group, Activecount () is used to get the number of threads.
    5. Synchronized&&volatile: A race condition can be caused when a thread accesses the same object's same resource.
    6. Wait and notify: Wait (), notify (), Notifyall () control thread releases the lock on the object.

Parallel APIs

    • Lock: The implicit lock object relative to the thread model, lock provides an explicit lock operation to simplify the application.  Executors: Provides a set of HIGHLEVELAPI for performing and managing parallel tasks. Concurrentcollections (Parallel Collection): Contains a set of data structures that support parallel processing, greatly simplifying the difficulty of parallel programming. Atomicvariables (atomic variable): Reduces synchronization operations and avoids data inconsistencies. Fork/join Framework: Provides support for process operations.
    • with respect to the implicit lock object of the thread model, lock provides an explicit lock operation to simplify the application.  Executors: Provides a set of HIGHLEVELAPI for performing and managing parallel tasks. Concurrentcollections (Parallel Collection): Contains a set of data structures that support parallel processing, greatly simplifying the difficulty of parallel programming. Atomicvariables (atomic variable): Reduces synchronization operations and avoids data inconsistencies. Fork/join Framework: Provides support for process operations. The
    • Readwritelock:readwritelock interface defines read lock and write lock behavior, and you can return a lock operand using the Readlock (), Writelock () method. Reentrantreadwritelock is the primary operation class for the Readwritelock interface, and the Readlock () method returns the Reentrantreadwritelock.readlock instance, Writelock () Breaking the law will return the Reentrantreadwritelock.writelock instance.
    • The Condition:condition interface is used with lock, and the most basic usage is to achieve the function of the Wait (), notify (), Notifyall () method of object. The await (), signal (), Signalall () methods of condition can be considered as corresponding to the wait (), notify (), and Notifyall () methods of object.
    • Executor: Provides a set of HIGHLEVELAPI for performing and managing parallel tasks.
    • Scheduledthreadpoolexecutor:scheduledexecutorservice as the Executorservice sub-interface, as the name implies, allows you to work scheduling: Schedule () method is used to schedule runnable or callable instances to be executed once, and returns an instance of the future Subinterface scheduledfuture, for repetitive executions, using schedulewithfixeddelay () and Scheduleatfixedrate () method.
    • Forkjoinpool: The so-called divide and conquer problem, refers to the solution of these problems, can be decomposed into sub-problems of the same nature, sub-problems can be decomposed into smaller sub-problems, the same nature of sub-problems to solve and collect the results of the operation, the whole problem is solved.
      The Forkjoinpool differs from other executorservice operations in that it is chatting up the work-stealing calculus, and its established thread, if it completes the task at hand, will try to find and perform other tasks to establish the funding task, keep the thread busy, and effectively utilize the processor's capabilities. It is important to notethat the Forkjoin framework is suitable for computing dense tasks and is less suitable for situations where threading is easily blocked.
  1. Parallel Collection:copyonwritearrayset operates the set interface, which is used for a situation where there are very few write operations, and the use of iterators is frequent.

20145234 Huangfei "Java Programming" Sixth Week 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.