Gold three silver four, Java programmers who have just gotten an offer from Ant Financial share the experience of entering the big factory

Due to the intense tension during the interview, this article only lists some of the topics that I still remember.

After a long month of waiting, I finally learned from the interviewer that I had been accepted by Ant Financial a few days ago. Needless to say, the anxiety and pain during this period was not to be said. The moment I knew that I was admitted, the haze was wiped out.

The author is working with Alibaba’s Java R&D engineer. The interview process is 3 rounds of technical aspects and 1 round of hr.

The unexpected side

One side may be the resume side, so the question is relatively simple.

Difference between ArrayList and LinkedList

ArrayList is a resizable array. When more elements are added to the ArrayList, its size will grow dynamically. The internal elements can be accessed directly through the get and set methods, because ArrayList is essentially an array.

LinkedList is a double-linked list, which has better performance than ArrayList when adding and deleting elements. But it is weaker than ArrayList in terms of get and set.

Of course, these comparisons refer to comparisons when the amount of data is large or the operations are very frequent. If the amount of data and calculations is small, the comparison will be meaningless.

What will cause a memory leak

In Java, memory leaks are the existence of some allocated objects. These objects have the following two characteristics:

First of all, these objects are reachable, that is, in a directed graph, there are paths that can be connected to them;

Secondly, these objects are useless, that is, the program will not use these objects in the future.

If the objects meet these two conditions, these objects can be judged as memory leaks in Java. These objects will not be reclaimed by the GC, but they occupy memory.

What is thread deadlock and how to solve it

There are four conditions for deadlock:

Mutual exclusion conditions: The so-called mutual exclusion means that the process monopolizes resources for a certain period of time.

Request and hold conditions: When a process is blocked by requesting resources, it keeps on holding the acquired resources.

Non-deprivation conditions: The process has obtained resources and cannot be forcibly deprived before they are used up.

Circulating waiting condition: A kind of cyclic waiting resource relationship is formed between several processes.

Thread deadlock is caused by multiple threads accessing shared resources due to improper access sequence. Usually one thread locks a resource A and wants to lock resource B; in another thread, resource B is locked, and Also want to lock resource A to complete its own operation, two threads want to get the other's resources, and are unwilling to release their own resources, resulting in a situation where both threads are waiting and cannot be executed.

To solve the deadlock, we can start from the four conditions of the deadlock, as long as one necessary condition is destroyed, then our deadlock is solved. When using multithreading in Java, you must consider whether there is a deadlock problem.

What is a red-black tree? How to achieve it? time complexity

Red-Black Tree (RB Tree) is a special binary search tree. The red-black tree is a special binary search tree, which means that it satisfies the characteristics of the binary search tree: the key value contained in any node is greater than or equal to the key value of the left child, and less than or equal to the key value of the right child. In addition to this feature, the red-black tree also includes a lot of additional information.

Each node of the red-black tree has storage bits to indicate the color of the node, the color is red (Red) or black (Black). Characteristics of red-black trees:

Each node is either black or red.

The root node is black.

Each leaf node is black.

If a node is red, its child nodes must be black.

All paths from a node to the descendants of that node contain the same number of black nodes.

Regarding its characteristics, it should be noted that:

First, the leaf nodes in feature (3) are nodes that are only empty (NIL or null).

Second, feature (5), to ensure that no path will be twice as long as the others. Therefore, the red-black tree is a relatively close to balanced binary tree.

Java programmers who just got an offer from Ant Financial share the experience of entering the big factory

 

The specific implementation code is not posted here. To implement it, the basic operations that need to be included are adding, deleting, and rotating. After adding or deleting the red-black tree, the rotation method will be used. The purpose of rotation is to keep the tree with the characteristics of a red-black tree. There are two types of rotation: left-hand and right-hand.

The red-black tree is widely used, mainly to store ordered data. The time complexity of its search, insert, and delete operations is O(lgn).

TCP three-way handshake

Three-way handshake (three times handshake; three-way handshake) The so-called "three-way handshake" refers to how the amount of data sent each time is tracked and negotiated to synchronize the sending and receiving of the data segment, which is determined according to the amount of data received The number of data confirmations and when to cancel the contact after the data is sent and received, and establish a virtual connection.

In order to provide reliable transmission, TCP sends the sequence numbers of data packets in a specific order before sending new data, and requires confirmation messages after these packets are transmitted to the target machine. TCP is always used to send large batches of data. TCP is also used when the application needs to make confirmation after receiving the data.

Java programmers who just got an offer from Ant Financial share the experience of entering the big factory

 

The first handshake: When establishing a connection, the client sends a syn packet (syn=j) to the server, and enters the SYN_SENT state, waiting for the server to confirm; SYN: Synchronize Sequence Numbers.

The second handshake: the server receives the syn packet, it must confirm the client's SYN (ack=j+1), and at the same time send a SYN packet (syn=k), that is, the SYN+ACK packet, and the server enters the SYN_RECV state;

The third handshake: The client receives the SYN+ACK packet from the server and sends an acknowledgment packet ACK (ack=k+1) to the server. After this packet is sent, the client and the server enter the ESTABLISHED (TCP connection successful) state, which is completed three times shake hands.

Sudden two sides

After waiting for almost half a month, I suddenly received a call from the interviewer.

Introducing the project

How does Storm ensure consistency

Storm is a distributed stream processing system that uses anchor and ack mechanisms to ensure that all tuples are successfully processed. If the tuple is wrong, it can be retransmitted, but how to ensure that the wrong tuple is only processed once? Storm provides a set of transactional components Transaction Topology to solve this problem.

Transactional Topology is no longer maintained. Trident implements transactional topology, but the principle is the same.

Reference: https://dwz.cn/8bXRPexB

Talk about hashmap and whether it is thread safe

HashMap is based on the implementation of the Map interface of the hash table. In HashMap, null can be used as a key, and there is only one such key; there can be one or more keys corresponding to the value of null. The default size of the hash array in HashMap is 16, and it must be an exponent of 2. Both Hashtable and HashMap use Iterator. For historical reasons, Hashtable also uses Enumeration. HashMap implements Iterator and supports fast-fail.

The hash table is composed of an array + a linked list. It locates the object by hashing the key value, which can provide better performance than linear storage.

Java programmers who just got an offer from Ant Financial share the experience of entering the big factory

 

HashMap is not thread safe.

One billion Taobao purchase records, how to get the top ten most appearing

This is a typical problem of massive data processing with limited memory. Generally, the answers to such questions are nothing more than the following:

Divide and conquer, hash mapping, heap sorting, double bucket partitioning, Bloom Filter, bitmap, database index, mapreduce, etc.

There are many different scenarios for specific situations. You can search for these kinds of topics on the Internet to understand the routines, and you will basically be able to do them later.

Is there a linux system in normal times, how to check a certain process

ps aux|grep java view java process

ps aux view all processes

ps -ef|grep tomcat View all tomcat processes

ps -ef|grep --color java highlight the keyword to be queried

kill -9 19979 Terminate the process with thread number 19979

Talk about the difference between Innodb and MySIAM

The MyISAM type does not support advanced processing such as transaction processing, while the InnoDB type supports. The MyISAM type table emphasizes performance, and its execution is faster than InnoDB type, but does not provide transaction support, while InnoDB provides transaction support and advanced database functions such as external keys.

InnoDB does not support FULLTEXT type indexes.

InnoDB does not save the specific number of rows of the table, that is, when executing select count(*) from table, InnoDB scans the entire table to calculate how many rows there are, but MyISAM simply reads the saved number of rows. . Note that when the count(*) statement contains the where condition, the operation of the two tables is the same.

For fields of type AUTO_INCREMENT, InnoDB must contain only the index of the field, but in the MyISAM table, you can build a joint index with other fields.

When DELETE FROM table, InnoDB will not re-create the table, but delete row by row.

The LOAD TABLE FROM MASTER operation does not work for InnoDB. The solution is to first change the InnoDB table to MyISAM table, and then change it to InnoDB table after importing the data. However, the table that uses additional InnoDB features (such as foreign keys) does not work. Be applicable.

Talk about the jvm memory model, introduce the garbage collector you know

In fact, there is no concept of the JVM memory model. It should be the Java memory model or the jvm memory structure. The interviewer here must listen to which one is being asked before answering.

Can refer to: JVM memory structure VS Java memory model VS Java object model

You said you are in the direction of big data, and understand which big data frameworks

The author answered some zookeeper, storm, HDFS, Hbase, etc.

other problems

How to disrupt the order of 100 ordered integers?

How to design a reliable UDP protocol?

This is probably the case on the two sides. The question of storm consistency was suspected by the interviewer, and I was a little nervous, but I didn't answer it wrong, so I still need to have a clearer grasp of the knowledge.

Well prepared three sides

Introducing the project

Did not ask too much after the introduction of the project

Introduce hashmap

HashMap is really a high-frequency interview question. I have asked it in many interviews and must be mastered.

Introduce concurrency

Here you can talk about the entire concurrent system, including volatile, synchronized, lock, optimistic and pessimistic lock, lock expansion, lock degradation, thread pool, etc.

How to read and write bank account

I talked about read-write locks and possible deadlock problems

Talk about the difference between relational database and non-relational database

Advantages of non-relational databases:

Performance: NOSQL is based on key-value pairs, which can be imagined as the corresponding relationship between the primary key and value in the table, and does not need to be parsed by the SQL layer, so the performance is very high

Scalability: Also because there is no coupling between data based on key-value pairs, it is very easy to scale horizontally.

Usage scenarios: logs, buried points, forums, blogs, etc.

Advantages of relational databases:

Complex query: SQL statements can be used to conveniently do very complex data queries between a table and multiple tables

Transaction support: Enables the realization of data access requirements with high security performance.

Usage scenario: All logically related data storage

How to access the intermediate node of the linked list

For this problem, the first thing we can think of is to traverse the entire linked list first, then calculate the length of the linked list, and then traverse the second pass to find the middle position data. This way is very simple.

If the problem requires that the linked list can only be traversed once, how to solve the problem?

Two pointers can be established, one pointer traverses two nodes at a time, and the other node traverses one node at a time. When the fast pointer traverses to an empty node, the position pointed to by the slow pointer is the middle position of the linked list. This solution to the problem is called For the fast and slow pointer method.

Talk about inter-process communication, and their differences

Inter-process communication refers to the propagation or exchange of information between different processes. There are usually pipes (including unnamed pipes and named pipes), message queues, semaphores, shared storage, Sockets, Streams, etc.

A specific process for accessing Taobao web pages, from obtaining the IP address to how to return the relevant content

First resolve to the server address through DNS, and then reverse proxy, load balancing server, etc., find a machine in the cluster to actually execute your request. It can also introduce CDN, page caching, Cookie and session, etc.

This process also includes the three-way handshake, what is included in the HTTP request, the status code, etc., and the seven layers of OSI can be introduced.

After the server receives the request, it will execute the business logic, and the execution process can be introduced separately according to the MVC.

Whether to call other RPC services or asynchronous messages during service processing, this process includes service discovery and registration, and message routing.

Will the database be cached after the last query? Is it a relational database? Will it sub-databases and tables or what operations will it do?

For databases, sub-database and sub-tables are necessary if the amount of data is large. General business is based on a sub-table field to perform sub-tables based on the modulus. When doing database operations, the data read and write are also determined according to the same rules. Which table corresponds to the operation. This kind of realization is also open source, such as Ali's TDDL has this function. Sub-database and sub-table also involve many technologies, such as how to set the sequence, how to solve hot issues, etc.

Finally, encapsulate the processing result into a response and return it to the client. The browser then renders the page.

Anxious hr side

What setbacks did you encounter

This kind of question mainly examines whether the interviewer can persevere when encountering difficulties, and can see his problem-solving ability.

You can briefly describe the setbacks, and explain how you overcome them and what are the final gains.

career planning

Show your determination, first of all, you are not ready to continue studying, you must hire a job. Then I said that I will not change industries or jobs in the short term. I like it better. I hope that I can stick to it for a few years to see my own interests and then plan and so on.

Knowledge of Ali

This is a short answer, just exaggerate.

Is there anyone to admire

I said James Harden, Miss Hr actually laughed.

This can be said to be some IT giants.

Where do you want to work

This question is answered decisively in the city where the company is located.

other problems

Are there any hobbies that can be performed on stage?

Memorable things

At last

Share some interview questions of this programmer preparing for the interview with a big factory, hoping to help everyone.

Friends who need information, click here to get it!

Guess you like

Origin blog.csdn.net/m0_46995061/article/details/115265945