From sending messages to Baidu take you to play the network

preface

When you interview for a development position, do you always feel that the interviewer is asking you tough questions? Clearly oneself prepares the knowledge all very sufficient, why unluckily asks is not oneself grasps? Xiaobian here to tell you that you are the lack of corresponding interview questions to do guidance, there is no direction. The interview builds the rocket, the entry screws, therefore, the interview is very important for everyone.

Xiaobian should be everyone’s consideration, to share with you tsinghua graduate big guy sorted out the Java network programming interview questions. Because the content is a little bit too much, xiaobian here only give you part of the content screenshots out of the introduction, each section has more detailed content.

First to share the Java network programming interview questions directory

Secondly, it is the introduction of several small knowledge points and answers

1, TCP and UDP differences

TCP is a connection-oriented flow transmission control protocol. It has high reliability, ensures the correctness of transmitted data, and has a retransmission mechanism to prevent data loss or disorder.

UDP: a connectionless datagram service. It does not check or modify datagram and does not need to wait for the reply of the other party. Packet loss, repetition, and disorder may occur, but it has good real-time performance.

2. The specific process of the three-way handshake when a TCP connection is established and the four-way handshake when a connection is disconnected

1. Three-way handshake protocol used to establish the connection, specifically referring to:

The first handshake is when the client connects to the server

L After the server accepts the request from the client for the second time, it sends a message to the client, which means that I am ready and you have connected with me

L The third handshake is sent by the client to the server to confirm the second handshake. The client and server then communicate.

2. The four handshakes of disconnection are as follows:

The disconnected end sending the close request is the first handshake

The other end needs to acknowledge the close after receiving the disconnection request, sending a message, which is the second handshake

L After sending the confirmation message, send the close message to the peer. To close the connection to the peer, this is the third handshake

L After the disconnected end receives the message, it enters the important state of time_wait, which is often asked by the interviewer. The last handshake is after the disconnected end receives the message. Confirmation of the message.

What is blocking IO? What is non-blocking IO?

Before we look at blocking and non-blocking I/OS, let’s look at the next specific I/O operation.

Generally speaking, I/O operations include read and write operations to hard disks, sockets, and peripherals.

When a user thread initiates an IO request operation (this article uses the read request operation as an example), the kernel checks to see if the data to be read is ready. In the case of blocking IO, if the data is not ready, it will wait until the data is ready. For non-blocking IO, if the data is not ready, a flag message is returned telling the user that the data the thread is currently trying to read is not ready. When the data is ready, the data is copied to the user’s thread and a complete IO read operation is completed. In other words, a complete IO read operation consists of two phases:

1) Check whether the data is ready;

2) Copy data (the kernel copies data to the user thread).

So the difference between blocking IO and non-blocking IO is in the first phase, if the data is not ready, whether to wait while checking whether the data is ready or just return a flag message.

In Java, traditional IO is blocking IO, such as reading data through a socket. If the read() method is not ready, the current thread will block in the read method until it returns data.

In non-blocking IO, when data is not ready, the read() method should return a flag telling the current thread that the data is not ready, rather than waiting.

32. What about HTTP protocol?

HTTP is short for Hyper Text Transfer Protocol. It is used to Transfer hypertext from the World Wide Web server to the local browser.

HTTP is a TCP/ IP-based communication protocol to transfer data (HTML files, image files, query results, etc.).

How HTTP works

The HTTP protocol works on a client-server architecture. As the HTTP client, the browser sends all requests to the HTTP server, namely the WEB server, through the URL.

Web server: Apache server, Nginx, IIS server (Internet Information Services) and so on.

The Web server sends response information to the client based on the received request.

The default HTTP port number is 80, but you can change it to 8080 or some other port.

HTTP three points to note:

L HTTP is connectionless: Connectionless means to limit processing to one request per connection. The server disconnects from the customer after processing the request and receiving the reply from the customer. In this way, transmission time can be saved.

L HTTP is media independent: this means that any type of data can be sent over HTTP as long as the client and server know how to handle the data content. The client and server specify the appropriate MIME-type content type to use.

L HTTP is stateless: HTTP is a stateless protocol. Stateless means that the protocol has no memory for transaction processing. The lack of state means that if the previous information is needed for subsequent processing, it must be retransmitted, which can result in an increase in the amount of data transferred per connection. On the other hand, the server responds faster when it doesn’t need the previous information.

34. Describe the HTTP server response messages.

The HTTP response also consists of four parts:

L status line

L Message header

L a blank line

L Response body


HTTP / 1.1 200 OKCopy the code
Date: Mon, 27 Jul 2009 12:28:53 GMTCopy the code
Server: ApacheCopy the code
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMTCopy the code
ETag: "34aa387-d-1568eb00"Copy the code
Accept-Ranges: bytesCopy the code
Content-Length: 51Copy the code
Vary: Accept-EncodingCopy the code
Content-Type: text/plainCopy the code

Finally, Java Web programming interview questions


Due to space limitations, xiaobian here will not do too much introduction, need this [Java network programming interview questions] document partners, you can forward attention to xiaobian, private letter xiaobian “interview” to get it!

Thank you for your cooperation and trust, and strive to achieve a better self.