In March 2020 interview summary

Interview friends come to an end, in April we should entry of the new company, and will now face questions are summarized below

 

  • java-based issues
  1. HashMap principle underlying (asked no less than 5 times)
    to answer this question from the bottom to answer, first answer is the backbone of the structure is an array structure, according to data Hash values into one bucket, the initial size defaults to 16, Hash collision if there this data will be placed in the bottom of the barrel, with a linked list.
    This time to point out the problem, if the list is too long leads to excessive Hash collision will cause the query worst time complexity is O (N), so after JDK1.8, when the list is longer than 8 list into a red-black tree to facilitate the inquiry.
    Follow-up may be asked whether HashMap thread-safe, easily leads ConcurrentHashMap segment lock, the lock of the best segments of the principles to understand, such as segmented lock Segment, etc., and you can say about this expanding problem, it is best to start specifying the appropriate size, or a resource consumption.

  2. It should be noted that the interviewer might ask to red-black tree, the difference between binary search tree, balanced binary tree, and why is the red-black tree, interested friends can continue to expand.
  3. ArrayList question

    the issue of ArrayList I met the interviewer let me talk about how to work usually used ArrayList encountered this problem I usually answer first ArrayList is not thread-safe, and secondly you can talk about ArrayList the underlying principle (Object array with an initial size of 10), as well as expanding problem ArrayList threshold value of 0.75 set of size, if the interviewer continue to ask why it is 0.75, I usually answer that I have not studied in depth, but 0.75 is belonging to the optimal strategy in space and time taken.

    Finally, you can talk about traverse the ArrayList that ArrayList is automatic expansion, it does not support the foreach traversal encountered this problem in the actual development.
  4. Collection Collections Framework

    encounter this problem I usually say is the root Collection Collections Framework, and then talk about the set, Hash and other structures, say some of their differences, and thread-safety issues and how to solve thread safety issues.
  • java multi-threaded (multi-threaded been asked)
  1. Talk about java multithreading you understand how to ensure thread-safety

    answering this question I will first answer example, I open a new thread may be new Thread (). Start to open up a new thread, you may use the thread pool at work As for how to use multiple threads you can tell the general development process is threaded operation resource, where you can install a force, Ali talk about development manual does not allow java own thread pool, and not new thread. Companies use to write their own thread pool.

    How to understand the thread control resource classes can give an example, for example, I have a Class Count count class and main method understood as there are many threads, I want to use multiple threads to manipulate the counting classes, ensure his atomicity, visibility of prohibiting instruction rearrangement of these three characteristics in my blog about Voliate keywords blog there are introduced. We need to ensure that these characteristics play in ensuring the three characteristics will ensure the thread safety.

    JUC This package can talk about the interviewer, the bonus items such countDownlatch the like, comprising atoms class Automic.
     
  2. Java will be asked to kind of lock you know well, and your favorite lock

    this issue I will not elaborate on the blog, that my answer to this question ideas.
    First, I will answer my common type of lock: Lock fair, unfair lock (synchronized), shared lock, pessimistic locking, optimistic locking.
    In the next process, I will focus on talk about CAS lock, can lead to Automic class, such as the underlying atomic +1 class is how to achieve, you can say you've seen the source code, the underlying is a do while loop.
    The next question is particularly important, talked about CAS lock you will talk about the ABA problem and how to solve the problem of ABA, I related issues are detailed in the blog about the CAS in.
     
  3. Parameters java thread pool, and why not use java own thread pool

    thread pool parameters: I often answer is the core number of threads, the maximum number of threads, blocking queue, time settings, etc. ... why not use its own I usually answer thread pool is blocking queue set to Integer.MAX roughly more than 2.1 billion which is extremely unreasonable.
     
  4. How to thread returns parameters

    to ask me this question is a foreign company, thanks to my brother, "Big Brother" in an interview a few days ago we discussed this issue. My answer is Runable the interface does not return parameters, this time using the Callable interface return parameters, the specific use to go down to look at, but you know the result Callable interface to answer questions on it.
     
  5. About multithreaded title

    may make you do some multithreading issues, such as these in order to print 10 times 20 times 30 times AAA, BBB, CCC generally encountered such problems should use multithreaded operating resource class, I usually use Lock plus Codition solve these problems.
  • Message Oriented Middleware (I usually answer kafka)
  1. Intermediate key used in the development of their own

    have a business scenario my friend told me, in this extremely grateful lili students. For example, we all know that playing the game of game items will be distributed in the mail, sometimes some delay, here realized as follows. Usually set to an asynchronous call, all incoming parameters, if it detects all reasonable parameters, then the front-end will return success, then this news put to kafka, make follow-up in consumer spending kafka message, if the call is unsuccessful calls consume many times, but once the parameters will give users the right to return the props will be released after 24 hours. This is an application process. Specific can combine their own projects, to describe the problem.
     
  2. How kafka guarantee the order of the message

    such a message I'd like to make purchases in accordance with 1,2,3 .... labels, how to order consumer generally two ways, 1. All messages will be placed in a partion, partion itself a queue, put the time to ensure order, the consumer can also be the order of the consumer. 2. pull into the message queue into the N having the same key is placed in the same queue, but I have not used this method, I do not know how to set.
     
  3. How kafka ensure idempotency

    idempotency guarantee kafka may be used PID, setNumber and kafka plus transaction specific use will not repeat them here.
     
  4. How kafka ensure that messages are not lost

    during the interview the interviewer gave me a case is described, such as consumer kafka, this news just consumption but your program hangs up, then you think of kafka data has been consumed, but in fact the program suddenly go wrong this fact, your data is not to be consumed without being processed program, how to solve this problem.

    My answer is that this is not really kafka lost data, in fact, we feel that people use improper kafka data loss, and to solve this problem is best to use a manual offset, after executing the program manually offset proof has been consumed not It will be problems mentioned above.
  • NoSql problem
  1. Why NoSql, and NoSql your project

    NoSql is not only sql sql is just, because sql is persisted to the hard drive, relatively slow, can not meet the ever-changing needs. I generally use the redis, cache operation.
  2. redis persistent way

    redis There are two persistent ways, one is RDB, one is AOF, where you want to explain the difference between the two, such as AOF data can be stored one second before the problem occurs, usually Two general development persistence are open.
     
  3. redis persistent files can not be restored problem how to do

    generally persistent data written to the appropriate .RDB and .AOF file, the data is written ungrammatical when unrecoverable problems that may arise, then use the command will check does not meet the data syntax to delete, and then rolled back no problem.
     
  4. redis out of sync with the database how to handle the data

    this is my interview questions interview ICBC (Love deposit does not exist) in a interview questions, my answer is that during the Update statement, delete data in redis while the data after the update is complete write to redis in.

    Then he asked me to deal with problems that may arise, the problem you know what? Hey I smile, then talk about a problem with this implementation may arise, such as when updating the data has not been completed, there is a query sql, found no redis, may be found in the database, the data is written at the same time it will be found to redis, but after the update is complete you will re-write again redis, and read user data is dirty, wasteful, and user data resources are not allowed to read, but not taking into account the write operation, and the probability is very small general It would be so treated.

    But he still rode me, you want me to solve this problem, I was already in the MMP, but still grinning, said, is not kafka and expiration policies used in combination with (I do not really understand this strategy, not we write out the pit), such as the emergence of a probability of 0.1, 0.01 is used in combination, greatly reduced this case, we passed a perfunctory question, in fact, I now do not really understand, I hope you will add.
     
  5. Since redis redis why can not replace persistent mysql

    reason I ask this question to me people are stupid, and wanted to answer because mysql easy to use ah! But still bite the bullet and go on to answer, answer the following ideas

    first I said mysql data types more to meet increased demand, then overtaken by a good visual mysql table data is very clear, and there are a variety of mysql storage engines to meet more and more complex needs, he took advantage of some mysql would say avoid this problem is over, welcome to add to this problem.
     
  6. redis transaction

    redis affairs and we usually think of the transaction may be different, such as operating a transaction 1,2,3, 1,2 success 3 failure. But redis performs operations 1,2 3 does not perform it failed to pay particular attention.
     
  1. Database indexes underlying

    database underlying index is a B + tree, and interested friends to study the B-tree, the interviewer will ask whether the index is, the better is how well you usually use the index, a composite index and I will answer substructure B-tree.
     
  2. How to deal with encounters slow sql

    general use explain command check to see if the index, ref field, and the index is to use all, whether a full table scan, here we must pay attention to use the index to be consistent type of data, do not create a String types of indexes, but with the use of Integer, will lead to index failures are taboo.
     
  3. select. . . . . . . for update this statement is what is the meaning

    of this statement is a row lock, only to put this statement will be processed the following process.
     
  4. Database optimization strategies of

    this there are many online introduction, to form their own ideas, such as sub-library sub-table, separate read and write, can say some database parameters such as join_buffer_size can be appropriately adjusted large these parameters, showing that enrich their knowledge.
  • java framework
  1. spring of IOC and AOP

    answer this question first thing to say is what IOC and AOP, such as inversion of control is to talk about the IOC, why is it called inversion of control, because we had to write a program to keep the new objects that right now Spring pay out to be assembled, corresponds to handover control rights. Then you can say that the underlying implementation is the factory mode IOC plus reflection, the AOP is dynamic proxy, these details are specifically described.
     
  2. Have you seen the source of those frames

    reason this problem is very big, and I am forced to because we are not ignorant of what the great God, every day, to get the source code, usually I will talk about Spring loaded an object of this process section of source code, specifically I do not said the province's misleading you, can give you a idea, some say you are good at, and then half-way talk about why you wrote the source code to solve the problem, I joined resolve circular dependencies in this process and other issues such as a BB and CC rely rely rely on the a which is equivalent to a circle, kept going round in circles, then spring the solution may be put out on the cache a, when C can no longer rely on a jump out of this cycle.
     
  3. Persistence layer framework that you use to

    this problem with their own say good, I usually say JPA and mybatis, then will talk about the secondary cache and redis mybatis used in combination, this can not be side-tracked by redis holding his nose go here appreciate my good based Friends of Hua Yu told me about this issue.
  • java algorithm and factory pattern (these extremely important, ICBC is a good dynamic programming did not answer directly carried away)
  1. Simple arithmetic problems such as taking the intersection and go repeat (as Hashmap With extra storage space)

    asked me how to interview two sets foreign companies out of their intersection part, my answer is to traverse a collection, put it on the Map then iterate through the second set if the Map contains is the intersection of the problem was successfully answer

    there is a question asked me one million telephone numbers, there are a lot of duplication, how to remove repeat, I am also using hashMap If you include it shows there is a deposit just fine.
     
  2. Are there ring chain

    problem encountered in a traditional pen questions in the enterprise, I offer up I did not go hey hey! ! Finger by speed, if there is a ring, it will be the ferrule, the speed of the pointer will meet in one place.
     
  3. Dynamic Programming

    This is a kind of chronic problem, and is often asked, tell the truth I am also very large head, or the breakdown of this problem. 1. count into question 2. Question 3. feasibility of most value, and interested friends Forum Search my blog, there are some simple description of the problem, the problem is not to see a one week will be able to, or want to do more .... Of course, I'm not good at.
     
  4. Issues related to the binary tree

    binary tree usually ask some binary tree traversal, and what the search tree, balanced tree, thanks again for the lovely lili recommend to my information, look at this one I feel almost
    https://github.com/labuladong/ fucking-algorithm / blob / master / % E6% 95% B0% E6% 8D% AE% E7% BB% 93% E6% 9E% 84% E7% B3% BB% E5% 88% 97 /% E4% BA% 8C% E5% 8F% 89% E6% 90% 9C% E7% B4% A2% E6% A0% 91% E6% 93% 8D% E4% BD% 9C% E9% 9B% 86% E9% 94% A6. md

     
  5. Factory mode

    I interviewed Ali asked me to use my factory pattern in the usual development to those, I did not see them, not answer it was carried away ....... later compiled some for your reference

    I think replied with two familiar design patterns like, I usually say that the strategy pattern and chain of responsibility pattern, such as code and there are many if else form a strong coupling between the code, you can query using progressively decoupled chain of responsibility pattern. Interested friends Forum Search b station.

    https://www.bilibili.com/video/BV1G4411c7N4?from=search&seid=1076934648693624301




    I encountered is probably the above subject, but in fact a lot of things difficult to show it in a blog, such as dynamic programming algorithm title, Spring source. Feeling still need time to accumulate constantly sum up, thanks to my friends to cheer me and chat with me, make me a lot of progress during that time, to Oliver! ! !


     
Published 13 original articles · won praise 15 · views 723

Guess you like

Origin blog.csdn.net/weixin_39475445/article/details/105310271
Recommended