I. Foundations
1. Data types
Basic types: int, long, short, byte, char, double, float, bool
Packaging types: Integer, Long, Short, Byte, Character, Double, Float,Boolean、BigInteger、BigDecmail
BigIntegerBigInteger, BigDecimal does not have a corresponding basic type, mainly used in high-precision operations, BigInteger support arbitrary precision of the integer, BigDecimal support arbitrary precision with a decimal point of the operation.
Similarities and differences between basic types and wrapper types:
1, in Java, everything is an object, but the eight basic types are not objects.
2, the declaration of the different ways, the basic types do not need to be created through the new keyword, while the encapsulated types need the new keyword.
3, the different storage methods and locations, the basic type is directly stored in the value of the variable saved in the stack can be accessed efficiently, encapsulated types need to point to the instance through the reference, the specific instance saved in the heap.
4, the initial value of the different, encapsulated type of the initial value of null, the initial value of the basic types depending on the specific type, such as int type of the initial value of 0, boolean type for false;
5, the use of different ways, such as cooperation with the collection of classes can only be used when the use of packaging type.
6, when to use the wrapper class, when to use the basic types, look at the basic business to determine: this field allows null values, if null values are allowed, it is necessary to use the wrapper class, otherwise the value type can be used, such as generic and reflective call function. , you need to use the wrapper class!
2, what are the common IO models and what is the difference between BIO, NIO, AIO in Java?
The application program makes IO calls (system calls) to the operating system's kernel, and the operating system's kernel is responsible for performing the specific IO operations. In other words, our application program is actually just initiating the IO call, and the kernel of the operating system is responsible for the execution of the specific IO operation.
Under UNIX systems, the IO model consists of a total of five types:Synchronous Blocking I/O、Synchronous non-blocking I/O、I/O Multiplexing、Signal Driver I/O cap (a poem)Asynchronous I/O.
BIO:Bolcking I/O, a synchronous blocking IO model, where the application initiates a read call and then blocks until after the kernel copies the data into user space.
It is fine when the number of client connections is not high. However, when faced with 100,000 or even millions of connections, the traditional BIO model is powerless. Therefore, we need a more efficient I/O processing model to cope with higher concurrency.
NIO:Non-blocking I/O, the synchronous non-blocking IO model, the application will always initiate the read call, and during the time it waits for the data to be copied from the kernel space to the user space, the thread remains blocked until the kernel copies the data to the user space. The synchronous non-blocking IO model is really an improvement over the synchronous blocking IO model. By polling, it avoids blocking all the time. However, there are also problems with this IO model:The process of an application constantly polling I/O system calls for data readiness is very CPU intensive.
Addressing the above issues:I/O multiplexing model
In the IO multiplexing model, the thread first initiates a select call to ask the kernel if the data is ready, and then when the kernel has the data ready, the user thread initiates a read call. the process of the read call (the data from the kernel space ->user space) is still blocking.
Currently, the system calls that support IO multiplexing are select, epoll, etc. The select system call, which is currently supported by almost all operating systems, has the following features
- select call : A system call provided by the kernel that supports querying the available state of multiple system calls at once. It is supported by almost all operating systems.
- epoll call : The linux 2.6 kernel, which is an enhanced version of select calls that optimizes the efficiency of IO execution.
NIO in Java has a very importantSelector The concept, which can also be referred to asmultiplexer. With it, multiple client connections can be managed with just one thread. Client data is served only when it arrives.
AIO: Asynchronous I/O, asynchronous IO model, asynchronous IO is based on the event and callback mechanism to achieve, that is, the application operation will be returned directly after the operation, will not be blocked there, when the background processing is complete, the operating system will notify the appropriate thread for subsequent operations.
II. Containers
1、
III. Complications
IV. JVM