Learning face-to-face scriptures - 2

Link: https://www.nowcoder.com/discuss/811065
Source: Niuke.com

1. http status code

The HTTP status code indicates the return result of the client's HTTP request and marks whether the processing on the server side is normal or an error occurred. It is very important to be able to judge whether the request is processed correctly according to the returned status code.
The status code consists of 3 digits and a reason phrase (three decimal numbers, the first decimal number defines the type of status code)
HTTP status codes are divided into the following 5 types:
category reason phrase
1xx : Information (information status code ) The accepted request is being processed
2xx : Success (success status code) The request is processed normally
3xx : Redirection (redirection status code) Additional operations are required to complete the request
4xx : Client Error (client error status code) The server cannot process the request
5xx : Server Error (server error status code) Error in server processing request

For details, see:
The interviewer asks you about the HTTP status code, do you dare to answer it?
Common HTTP status codes (14 types)

2. The difference between get and post

Both GET and POST are two methods of sending requests in the HTTP protocol.

At the same time, the bottom layer of HTTP is TCP/IP. So the bottom layer of GET and POST is also TCP/IP, that is to say, GET/POST are both TCP links. GET and POST can do the same things.

However, due to HTTP regulations and browser/server limitations, they show some differences in the application process.

(1) post is more secure (it will not be used as part of the url, will not be cached, saved in server logs, and browser browsing records) (
2) the data sent by post is larger (get has a url length limit)
(3) post can send more data types (get can only send ASCII characters)
(4) post is slower than get
(5) post is used to modify and write data, and get is generally used for operations such as searching, sorting and filtering (Taobao, Alipay's search queries are all submitted by get), the purpose is to obtain resources and read data

In addition to the above points, there is another major difference between GET and POST. Simply put,
GET generates one TCP packet; POST generates two TCP packets.
For GET requests, the browser will send the http header and data together, and the server will respond with 200 (return data);
for POST, the browser will send the header first, the server will respond with 100 continue, the browser will send data, and the server will respond 200 ok (return data).

For details, see: The difference between the two basic request methods of GET and POST

Can the post be spelled on the url?

Yes, because GET/POST are both TCP connections, they can do the same thing, so it is technically feasible to add request body to GET and url parameters to POST.

3. Three paradigms of database

The purpose of the three paradigms is to establish a database with less redundancy and a reasonable structure, and certain rules must be followed when designing the database. In a relational database, this rule is called a paradigm. A paradigm is a summary that meets a certain design requirement. To design a well-structured relational database, certain paradigms must be met.

  • First Normal Form (1NF, Normal Form): Attributes should not be separable . Example: If you use "phone" as an attribute (a column), it does not conform to 1NF, because the attribute of telephone can be decomposed into home phone and mobile phone... If you use "mobile phone" as an attribute, it is in line with 1NF;
  • Second Normal Form 2NF: Each non-primary attribute is completely dependent on the primary attribute set (candidate key set), ensuring that each column in the table is related to the primary key and eliminating partial dependencies. ;
  • The third normal form 3NF: On the basis of 2NF, non-primary attributes do not transitively depend on primary attributes, ensuring that each column is directly related to the primary key column, not indirectly, eliminating transitive dependencies and dependencies on non-primary attributes.

Constructing the database according to the three paradigms can reduce redundant data, modification exceptions, deletion exceptions, insertion exceptions and other exceptions.

For details, see: Detailed Explanation of the Three Paradigms of Databases

4.Mysql index, what principles need to be followed

For details, see:
Principles that MySQL needs to follow in creating indexes
Java interview questions-what problems do indexes solve? What principles should be followed?

If I build an index on the three fields of abc, can I use where b<1 and a=1 when querying?

Works, but not recommended. When querying, SQL statements should be optimized as much as possible.
Try to avoid using !=, <, operators in the where >clause or judging the null value of the field, otherwise the engine will give up using the index and perform a full table scan.
(here is not right now)

Well, how many indexes are used in this sql?

ab is used
(this is not right now)

What fields are suitable for indexing

Indexes are built on certain columns in the database table. Generally speaking, indexes should be created on these columns, for example:

  1. On the columns that often need to be searched, the search speed can be accelerated;
  2. On the column as the primary key, enforce the uniqueness of the column and the arrangement structure of the data in the organization table;
  3. On the columns that are often used in connection, these columns are mainly some foreign keys, which can speed up the connection;
  4. Create indexes on columns that often need to be searched according to the range, because the index has been sorted, and the specified range is continuous;
  5. Create an index on the column that often needs to be sorted, because the index is already sorted, so that the query can use the sorting of the index to speed up the sorting query time;
  6. Create indexes on the columns that are often used in the WHERE clause to speed up the judgment of conditions.

For details, see: Advantages and disadvantages of MySQL database indexing and what kind of fields are suitable for indexing

5. There are 8G files on the disk, all of which are ints, and the memory is only 2G. I want to sort the files, how do you plan to sort them?

Outer sorting: path merge plus loser tree

For details, see:
External sorting algorithm summary
Java implements external sorting

6. What is lru lfu, and where is this algorithm used?

Cache Elimination Algorithm

For details, see: An article to understand the cache elimination algorithm LRU and LFU

7. What is the difference between http https?

HTTP is Hypertext Transfer Protocol and HTTPS is Hypertext Transfer Protocol Secure Sockets Layer.
The HTTP protocol is used to transmit information between the web browser and the website server. The HTTP protocol sends content in plain text and does not provide any form of data encryption. If an attacker intercepts the transmission message between the web browser and the website server , you can directly read the information in it. Therefore, the HTTP protocol is not suitable for transmitting some sensitive information, such as: credit card number, password and other payment information. For HTTPS, for the security of data transmission, HTTPS adds the SSL protocol on the basis of HTTP. SSL relies on certificates to verify the identity of the server and encrypt the communication between the browser and the server.

The main differences between the two are:

  • The https protocol needs to go to CA to apply for a certificate. Generally, there are few free certificates, so a certain fee is required.
  • Http is a hypertext transfer protocol, information is transmitted in plain text, and https is a secure ssl encrypted transfer protocol.
  • http and https use completely different connection methods and different ports. The former is 80 and the latter is 443.
  • The http connection is very simple and stateless; the HTTPS protocol is a network protocol constructed by the SSL+HTTP protocol that can perform encrypted transmission and identity authentication, which is safer than the http protocol.

For details, see: The difference between HTTP and HTTPS

8. What is the difference between tcp udp

User Datagram Protocol UDP:
(User Datagram Protocol)

Connectionless
supports one-to-one, one-to-many, many-to-one and many-to-many interactive communications.
The packets delivered by the application layer are directly packaged, and the packets
are delivered on a best-effort basis, that is, unreliable;
flow control and congestion control are not used.
The header overhead is small, only 8 bytes

Transmission Control Protocol TCP:
(Transmission Control Protocol)

Connection-oriented
Each TCP connection can only have two endpoints EP, which can only be one-to-one communication.
Reliable transport for byte streams
, using flow control and congestion control.
The minimum of the header is 20 bytes, and the maximum is 60 bytes

For details, see: Advantages, disadvantages and differences between TCP and UDP

9. What is the process from entering the domain name to seeing the page in the browser?

It is mainly the process of domain name resolution.
For details, see:
Interview question: From the user inputting the domain name in the browser to the browser displaying the page, what happened in the middle (working process)? Detailed explanation of the
whole process of DNS domain name resolution

10. Algorithm: a monotonic stack question.

Guess you like

Origin blog.csdn.net/qq_45884783/article/details/123101651