java network programming - face questions

 

Synchronous, asynchronous, blocking, non-blocking at 1. Network programming?

Synchronization: The function is called before did not get the results, do not call the results, no results are returned.
Asynchronous: function called before did not get the results, do not call the results, return status information.
Blocking: function called before did not get the result, the current thread suspended. Return after getting results.
Non-blocking: the function is called before did not get the result, the current thread is not suspended, it returns immediately.

Socket Programming how 2.Java achieve non-blocking mode?

NIO cost effective solution to the problem of threading multi-threaded server.

Not to respond to each client request and allocate a separate service threads use multithreading main purpose of the NIO,

But through the full use of multi-threaded processing power and latency to handle multiple CPU's, to achieve the purpose of improving service capabilities.

3. What is the serialization of java (serialization)?

It simply is to preserve the state of various objects in memory (that is, an instance variable, not a method),

And you can save the state of the object read out. Although you can use your own variety of ways to save the object states, but Java provides a mechanism should give you a good state of preservation of the object than yourself, and that is serialized.

4. need to serialize what circumstances? Sequence of notes, how to achieve java serialization (serialization)?

• When the state of the object you want to save the memory to a file or database in time;

• When you want to use a socket transfer object on the network time;

• When you want to transfer object when the RMI;

Serialization Considerations

1, if the subclass implements Serializable class does not implement the parent, the parent will not be serialized, but this time must have a non-parent constructor parameter, otherwise InvalidClassException throw an exception.

2, static variables are not serialized, it was kind of "food", not the object. Serialized object is stored in the state, i.e., non-static properties, i.e., instance variables. You can not save the class variable.

3, transient key variables can be modified to limit serialized. For do not need or should not be saved properties, should be added to the transient modifier. To serialized object class must be public (public).

4, the virtual machine is allowed to deserialize, depends not only on the class path and function codes match, a very important point is whether the two sequences of classes same ID is private static final long serialVersionUID = 1L.

5, Java serialization mechanism in order to save disk space, with specific storage rules, when a file is written to the same object, and the object's content will no longer be stored, but only store a reference again. Deserialization to restore the reference relationship.

6, serialized to the same file, such as the Second Amendment to the same object property values ​​to save time again, the virtual machine based on the reference relationship already know that there is one and the same object has been written to the file, therefore saves only the second write references, so when reading, it is the first save of the object.

In 5.java There are several types of flow? JDK provided for each type of flow for a number of abstract classes inherit, say what they are like?

JDK provides a stream inherits four categories:

The InputStream (input stream of bytes), OutputStream (output stream of bytes), Reader (character input stream), Writer (character output stream).

By flow classification:

Input streams: a program can read the data stream.
Output streams: a program stream data can be written thereto.

According to the data transfer unit Category:

Byte stream: byte (8 bits binary) processing units. Mainly for reading and writing binary data such as an image or sound.
Character stream: character (binary 16) processing units.
It is achieved by means of the byte stream. Byte character stream is a stream of the package, easy to operate. At the lowest level, all the outputs are input in byte format.
Suffix Stream is a stream of bytes, while the suffix is Reader, Writer is a character stream.

Classified by function:

Node Stream: stream class to read and write from a particular place, such as a disk or a memory area.
Flow Filter: Use stream as input or output node. Flow filtration using an existing input stream or output stream connections created.

6. Use JAVA SOCKET programming, server read a few characters, and then written to the local display.

After the client sends a connection request to the server, it is passively waiting for response from the server.

A typical TCP client to go through the following three steps:

1, to create a Socket instance: constructor establish a TCP connection to the remote host and port specified;
2, through the I / O stream socket communications with the server;
3, using the method of the Socket class close close the connection.

 

End service work is to establish a communication terminal, and passively wait for client connections.

Typical TCP server performs the following two steps:

1, to create a specified local port and ServerSocket instance, used to monitor the TCP connection request sent by the client at the port;
2 Repeat:
1) Call Accept ServerSocket () method to obtain client connection, and its return value Create a Socket instance;
2) to open a new thread Socket instance returned, and the Socket returned example I / O stream to communicate with clients;
3) communication is completed, using Close Socket class () method to close the client end of the socket connector.

7.TCP / IP handshake on several occasions when connected? There are times when a handshake release?

TCP three-way handshake to establish a connection process:

 

TCP four waved release process:

Guess you like

Origin www.cnblogs.com/shoshana-kong/p/10932309.html