Introduction to the--01 object of reading notes in Java programming thought (thinking in Java)

Source: Internet
Author: User

1.9 Containers

With regard to containers, the most common is the various implementation classes derived from set, list, and map in the collection interface, as well as the less useful but indispensable queue.

They all have the same point, that is, a data aggregation function similar to an array type is provided (some types are also implemented in arrays). Simply put, you can bind data of the same type to the same place (pointers, indexes) like an array and wait for use.

But the container sub-class (interface) is different from each other, has its own characteristics.

The dependencies of each container are as follows:

Set type

There is no repetition between child elements. For example, four elements such as "1,1,2,3" in the Set implementation class, the container is only "three-way" the three elements.

(but its concrete constructors and implementation methods and use have not been studied in depth, and so on to supplement).

List type

Child elements can be stored repeatedly. For example, four elements such as "1,1,2,3" into the set implementation class, the container is only "1,1,2,3" the four elements.

The bottom layer is still implemented by the array, and the default constructor constructs the array using the capacity of "10" (or, optionally, specifying the size of the capacity when instantiated).

When the number of child elements exceeds the capacity, a new array is constructed with a capacity of 1.5 times times the current array, before the current array is copied into the new array.

Map type

The child elements are stored in the form of <Key,Value> (that is, commonly said k-y form), where the Key part cannot be duplicated and Value can be duplicated.

Key is data that resembles a pointer or index, and is used to represent some kind of data attribute in value (which is typically unique). For example, the identity card (idm,identity document number) as the key, the personal information (info,information) as value, the map data composed of <idm,info> can be queried through the IDM info.

Queue type

The queue feature is used to implement the task's FIFO (Fifo,first in First out), common to the task store for producer-consumer mode messaging mechanisms, multithreaded applications, and so on.

The book concludes with a suggestion:

We can use the LinkedList build program at the outset, while optimizing system performance instead of ArrayList.

The application of this technique is a good combination of the efficient sequence of linkedlist and the efficient random acquisition characteristics of ArrayList .

In the 1.9.1 parameterized type, it is mentioned that using generics to standardize the type format , but not over-reliance on generics, you should also note that "generic erase" may cause problems.

1.10 creation and lifetime of objects

The book mentions:

Java uses dynamic memory allocation in its full form. Whenever you want to create a new object, use the New keyword to build a dynamic instance of this object.

...

For languages that allow objects to be created on the stack, the compiler can determine when an object survives and can automatically destroy it . However, if you create an object on a heap, the compiler knows nothing about his life cycle .

The different points of the stack and heap are:

    • The stack is stored in contiguous space and is sequentially executed (LIFO) so that it can know its life cycle.
    • Heap storage does not require contiguous space, so it is possible to use fragmented and irregular spaces effectively, but it is also difficult to determine whether the current heap data has been used (this introduces the different memory-recycling mechanisms of the JVM mentioned later).
1.12 Concurrent Programming

The book mentions:

Sometimes interrupts are required to handle time-intensive tasks, but for a large number of other problems, we just want to split the problem into multiple independent parts (tasks), which can improve the responsiveness of the program .

It is easy to confuse that multithreading improves the "responsiveness" of the program, rather than improving the "processing power"of the program.

Because field protection consumes resources and time when switching between threads, blind use of multithreading can result in degraded performance, meaning that we need to be aware of the suitability of the scenario when choosing whether to use multi-threading.

For example, there are three options for bio, NIO, and AIO for I/O operations, including:

    • BIO (Blocked input/output, blocking I/O) can be understood as a single-threaded case where the controller (CPU) waits for the I/O to complete before proceeding to the next step;
    • NIO (not blocked input/output, non-blocking I/O) also uses a single thread , but the controller (CPU) does not have to wait for I/O to complete, freeing the controller by handing I/O control to the DMA controller (you can do other things like: open new I /O);
    • AIO (Asynchroniezd input/output, asynchronous I/O) is the idea of using async, such as an asynchronous message mechanism that separates the producer (Producer) from the consumer (Consumer), in which case it usually requires multithreading , the aim is to make full use of the modern computer distributed, multi-processor architecture;

1.13 Java and the Internet

The book mentions:

The core idea of the client/server system is that the system has a central information storage pool (centrally Repository of information), which is used to store some kind of data, which usually exists in the database. You can distribute it to certain people or machine clusters as needed.

...

In summary, the information storage pool, the software used to distribute the information, and the machine or cluster on which the information and software resides are collectively referred to as servers. Software that resides on the user's machine communicates with the server to obtain information, process information, and then display it on a user's machine called a client.

From c/S to B/s, from client to browse, we can finally provide the service directly in the Web page without having to program it for different platforms (although it is much more convenient to know HTML).

And in the modern project also can not be separated from the central information storage pool mode , centralized data access is basically the server side of the decision, resulting in the class status of the server and user completely isolated-causing user to trust the server will "behave" the status quo, But instances of server credit bankruptcy have occurred.

Until the advent of the blockchain (Bc,block Chain) , breaking the status quo, provides a new way of thinking (but for now, not the perfect solution).

Images are referenced in:

Http://www.jb51.net/article/84821.htm

Introduction to the--01 object of reading notes in Java programming thought (thinking in Java)

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.