How many IO streams are there in Java?

Free Java interview questions: juejin.cn/post/693238… According to functions, it can be divided into: input and output. By type: byte stream and character stream. The difference between a byte stream and a character stream is that a byte stream transmits input and output data in bytes in 8 bits, while a character stream transmits input and output data in characters in 16 bits.

What if some fields in Java serialization do not want to be serialized? For variables that do not want to be serialized, use the TRANSIENT keyword modifier.

The transient keyword prevents serialization of variables in an instance that are modified with this keyword. When an object is deserialized, variable values modified transient are not persisted and restored. Transient can only modify variables, not classes and methods.

Why have a character stream when you have a byte stream? Whether a file is read or written, or a network is sent or received, the smallest storage unit of information is a byte. Why are I/O stream operations divided into byte stream operations and character stream operations?

A: Character streams are generated by the Java virtual machine converting bytes. The problem is that this process can be very time-consuming, and if we don’t know the encoding type, we can easily have garbled characters. Therefore, the I/O stream simply provides a direct interface to manipulate characters, which is convenient for us to stream characters. It is better to use byte streams if audio files, images, etc., and character streams if characters are involved.

What’s the difference between BIO,NIO and AIO? BIO: Block IO Synchronous blocking IO is the traditional IO that we usually use. It is characterized by simple mode and convenient use, and low concurrent processing capability.

NIO: New IO synchronous non-blocking IO is an upgrade of traditional IO. The client and server communicate through channels, realizing multiplexing.

AIO: Asynchronous IO is an upgrade of NIO, also known as NIO2, which implements Asynchronous non-blocking I/O operations based on events and callbacks.

This keyword understanding? The this keyword is used to refer to the current instance of the class. Such as:

class Manager { 
Employees[] employees;
void manageEmployees(a) {
    int totalEmp = this.employees.length;
    System.out.println("Total employees: " + totalEmp);
    this.report();
}

void report(a) {}}Copy the code

In the example above, the this keyword is used in two places:

This.employees. length: a variable that accesses the current instance of the Manager class. This.report () : calls a method on the current instance of class Manager. This keyword is optional, which means that the example above behaves the same if it is not used. However, using this keyword might make your code more readable or understandable.