Summary of Autumn Recruitment (Java back-end development)

The following summary is all some of the high-frequency questions I was asked during the autumn recruitment process. Some of the answers attached are summarized after consulting related articles and are also personal opinions. If there are errors, please point out!

A Java foundation

  1. What is the difference between Java and C language? What is so good about Java?
  2. How to understand the cross-platform nature of Java, compile once and run everywhere?
  3. What is the difference between object-oriented and process-oriented?
  4. How to understand the three characteristics of object-oriented: encapsulation, inheritance, and polymorphism?
  5. Are there any problems with class inheritance, and under what circumstances will inheritance be used?
  6. Why rewrite the equals method and rewrite the hashcode method?
  7. Deep clone and shallow clone
  8. Reflection related
  9. The realization principle of annotation
  10. Advantages and disadvantages of lambda expressions?
  11. What are the benefits of Stream programming? What is the difference between the termination method and the delay method? What is the significance of the termination method?
Two Java collections
  1. HashMap bottom layer implementation (JDK1.7 uses array + linked list; JDK1.8 uses array + linked list + red-black tree)
  2. Why does HashMap introduce red-black trees? Why not use other balanced binary trees and the like? What are the advantages of red-black trees? (The rotation of the AVL tree is more difficult to balance and debug than the rotation of the red-black tree and requires a higher number of rotations)
  3. What are the two conditions for a linked list to be transformed into a red-black tree? (①The length of the linked list reaches 8; ②The length of the table array used at the bottom of the HashMap reaches 64; if the latter is not satisfied, the expansion method will be triggered)
  4. Linked list length greater than 8 is converted into red-black tree, less than 6 red-black tree is converted into linked list; why not directly set to greater than 8 converted into red-black tree, less than 8 converted into linked list; (there is a difference of 7 in the middle for transition to avoid Linked lists and trees are frequently converted. If a HashMap keeps inserting and deleting elements, and the number of linked lists is hovering around 8, tree to linked list and linked list to tree will happen frequently, and the efficiency will be very low)
  5. The threshold for converting a linked list into a red-black tree is 8. Why not set it to another value? (Following the Poisson distribution, the probability that the length of the linked list exceeds 8 is very small)
  6. HashMap expansion mechanism, namely the resize method? (JDK 1.7 will recalculate the hash value of each element. JDK1.8 uses high-order operations (e.hash & oldCap) to determine whether the element needs to be moved. If the result of the operation is 0, the position of the element remains unchanged after expansion. The result value is 1, indicating that the position of the element has changed during expansion, and the new subscript position is equal to the original subscript position + the original array length)
  7. Steps of adding elements to HashMap (put method), calculating the number of collection elements (size method)
  8. Why is HashMap thread unsafe? (Adding elements at the same time and expanding the capacity at the same time cause data loss, and the infinite loop of jdk1.7 header insertion in reverse order leads to 100% CPU usage)
  9. The default load factor of HashMap is 0.75, why not set it to 1 or 0.5 (considering capacity and performance)
  10. A hash conflict occurs in the HashMap. Is the new node inserted into the head of the linked list or the end of the linked list? (Jdk1.7 uses the reverse order of the head to insert, which will cause an infinite loop; jdk1.8 uses the tail to insert in the positive order)
  11. How does Hashtable control that the key value cannot be null? (When the put method is called, it will first judge whether the value is null, if it is null, a null pointer exception will be thrown directly; for the key, the hash value calculated by Hashtable is int hash = key.hashCode(); directly take the object's hashcode, key If it is null, it will report a null pointer exception; while the hash value calculated by HashMap is return (key == null)? 0: (h = key.hashCode()) ^ (h >>> 16), if the key is null, the hash value is 0)
  12. The underlying structure of ConcurrentHashMap (divided into jdk1.7 and jdk1.8), what methods do jdk1.7 and jdk1.8 use to achieve thread safety? (Jdk1.7 uses segmented locks, that is, add ReentrantLock locks to each segment; jdk1.8 uses CAS mechanism plus synchronized locks)
  13. How is the size method in ConcurrentMap implemented? Under multi-threaded operation, if one thread is checking the size method and one thread is executing the put method, how does the bottom layer control the value calculated each time to be correct?
  14. The underlying implementation of HashSet? (Based on HashMap, the bottom layer of a new HashSet object is actually a new HashMap, and uses the default initial capacity of 16 and the default load factor of 0.75; when we add an element to the HashSet, we actually put an element into the HashMap and the key is present, value HashMap values are the same, is a static constant pRESENT, source code is: private static final Object PRESENT = new Object();)
  15. How does BlockingQueue implement the producer consumer model?
  16. What are the thread-safe lists? (Vector, CopyOnWriteArrayList, you can also use the synchronizedList method of the Collections class to convert the thread-unsafe List to thread-safe)
  17. Why is ArrayList query fast? (The bottom layer of ArrayList is based on the implementation of the array, which can be queried according to the element subscript. The query method is (array first address + element length * subscript, read the corresponding number of bytes based on this position), if the array is stored Object, how to locate the location of the element according to the subscript? (Each element of the object array stores a reference to the object. If the reference type is enabled, pointer compression occupies 4 bytes, and if it is not enabled, it occupies 8 bytes, so the object array also applies to the above Formula)
  18. Expansion of ArrayList? (The bottom layer of ArrayList is based on an array implementation, so creating an ArrayList will assign an initial capacity to the array, the default value is 10, because the length of the array must be specified to allocate space for the array; due to the characteristics of the array, the expansion of the ArrayList is to create a larger array , And then copy the original elements to a larger array, the core method of expansion is the Arrays.copyOf method)
  19. The difference between ArrayList and LinkedList is the time complexity of adding an element. Since the efficiency of adding elements to ArrayList is not as high as LinkedList, why do we usually use ArrayList more?
  20. Under what circumstances will ArrayList be used, and when will LinkedList be used? (If it's just ordinary access elements, use ArrayList, LinkedList is generally used as stack and queue)
  21. How to turn a Map collection into a stack? (My idea is to use TreeMap to achieve it. The key stores the elements to be stacked, and the value stores the order in which they are stacked, such as the timestamp. Then, the Comparator is rewritten and sorted according to the value. , When traversing the Map, the advanced one comes out)
  22. Does the Map collection have iterators? What are the methods to traverse all the elements in the output Map?
Three multithreading and Java lock
  1. Three methods of thread pool, seven parameters, four rejection strategies (you can talk about the Alibaba Development Manual for the use of thread pool specifications by the way)
  2. How to define the maximum number of threads? (Considering from CPU-intensive and IO-intensive)
  3. The five states of the thread pool (Running, Shutdown, Stop, Tidying, Terminated)
  4. What is the difference between the task execution process, excute method and submit method of the thread pool?
  5. The difference between Synchronized lock and Lock lock
  6. The Java thread is falsely awakened (the thread should be in the wait state but was awakened. The solution is that the wait method should be wrapped in a while loop instead of if)
  7. Three characteristics of JMM (atomicity, visibility, orderliness), eight interactive actions of main memory and thread working memory
  8. How volatile guarantees visibility (MESI cache coherency protocol)
  9. How volatile guarantees order (memory barrier-lock prefix instruction)
  10. The difference between synchronized and volatile (volatile is a non-locking mechanism, this mechanism can avoid thread context switching and scheduling problems caused by the locking mechanism. Therefore, the execution cost of volatile is lower than synchronized; volatile can only guarantee visibility and order ; Synchronized can ensure atomic visibility and order)
  11. How does the atomic class in the JUC package guarantee atomicity? (CAS mechanism and spin lock)
  12. What problems will the CAS mechanism cause and how to solve the ABA problem? (CAS can cause ABA problems, and the version number mechanism is used to solve ABA problems)
  13. The difference between pessimistic lock and optimistic lock, application? (The Synchronized keyword and lock locks in java use pessimistic locks; CAS mechanism is an implementation of optimistic locks)
  14. Fair locks and unfair locks (fair locks are first-come, first-served, and starvation will not occur; unfair locks will cause starvation, but it is more efficient, and the default locks are unfair)
  15. Spin locks and mutex locks, the advantages and disadvantages of spin locks? (Advantages: reduce the overhead caused by context switching and user mode kernel mode switching; disadvantages: cyclic waiting consumes CPU)
  16. Reentrant locks and non-reentrant locks (non-reentrant locks can easily lead to deadlocks, most locks are reentrant, such as Synchronized locks and ReentrantLock)
  17. JDK1.6 Synchronized lock upgrade (bias lock—lightweight lock—heavyweight lock)
  18. The underlying implementation of Synchronized lock, what is the lock, and how do other threads determine that the lock has been occupied?
  19. Four necessary conditions for deadlock and deadlock processing strategy
Four Mysql
  1. The difference between Myisam and InnoDB storage engine? (Myisam does not support foreign keys or transactions. It supports table locks. When a select operation is performed, table locks are automatically added to the involved tables. When an addition, deletion, and modification operation is performed, write locks are automatically added to the involved tables; InnoDB supports external The key also supports transactions, and supports row locks. When performing a select operation, no lock is added. When an addition, deletion, and modification operation is performed, a write lock is automatically added to the row involved)
  2. What is a gap lock? What happens when row locks are upgraded to table locks?
  3. What are the row locks of InnoDB? Are rows or indexes locked? (Record Lock, Gap Lock, Next-Key Lock; the index is locked, not the row)
  4. Why can repeatable read isolation level also solve phantom reads? (Phantom reading can be eliminated by Next-Key Lock)
  5. Four problems caused by concurrent transaction processing and transaction isolation level (lost update, dirty read, non-repeatable read, phantom read; read uncommitted, read committed, repeatable read, serialization)
  6. How to understand Mysql's default transaction isolation level can be read repeatedly?
  7. How is the ACID property of the transaction implemented? (Atomicity is achieved through undo log rollback; persistence is achieved through redo log redo log; isolation is achieved through locks and MVCC; and consistency is achieved through atomicity, isolation, and durability. Only these three Features to achieve transaction consistency)
  8. Clustered index, non-clustered index, back to table query, covering index;
  9. What happens when the index fails? (Violating the leftmost prefix rule, the column index on the right of the range query is invalid, the string does not add single quotes, the index column is operated, the head is fuzzy matching, the use of unequal! = or <>)
  10. explain analysis of execution plan, optimization of SQL statement
  11. Three paradigms of mysql (1NF means atomicity, 2NF means elimination of partial dependence, 3NF means elimination of transitive dependence)
  12. The underlying implementation of mysql index, why use B+ tree instead of B tree? (B+ tree IO times are less, more suitable for range query, query efficiency is more stable)
  13. Isn't the hash table lookup faster, why not directly use the hash table as the underlying data structure of the index? (Hash table does not support range lookup)
Five Redis
  1. Usage scenarios of the five basic data types of Redis
  2. Cache penetration, cache breakdown, cache avalanche
  3. Redis's expiration strategy and memory elimination mechanism
  4. Redis's zset underlying data structure, why use jump tables instead of red-black trees
Six framework related
  1. The realization principle of Spring AOP? (Based on the dynamic proxy mode, if the target class implements the interface, then use the dynamic proxy based on the interface, otherwise use the dynamic proxy based on subclass/cglib)
  2. What are the specific loading steps for Spring AOP?
  3. The difference between AOP and OOP, what scenarios are applicable to?
  4. The scope of Spring Bean, the life cycle of Spring Bean (the instantiation of Bean—initialize Bean—use Bean—Bean destruction)
  5. What are the advantages and disadvantages of the two timings of Spring container creation? (One is to create the Bean when the Spring container starts, and the other is to create it when the getBean method is called)
  6. The execution process of SpringMVC (you can talk about the adapter mode by the way)
  7. Mybatis's primary cache and secondary cache?
  8. The difference between # and $ in Mybatis?
  9. How does Mybatis realize batch insertion?
  10. In the xml file of Mybatis, can the SQL statement directly use the greater than sign and the less than sign? What symbol should be used instead?
Seven design patterns
  1. Proxy mode (application: one is to create a multi-threaded way using the Runnable interface to apply a static proxy; the other is Spring AOP to apply a dynamic proxy)
    reference article: https://blog.csdn.net/can_chen/article/details/107827629

  2. Adapter mode (application: one is to use the Callable interface to create multiple threads; the other is HandleAdapter in SpringMVC)
    reference article: https://blog.csdn.net/can_chen/article/details/106968769

  3. Factory mode (application: one is Spring IOC; the other is SqlSessionFactory in Mybatis uses simple factory mode)
    Reference article: https://blog.csdn.net/can_chen/article/details/105924115

  4. Singleton mode (usually you will need to tear the code of the singleton mode by hand, mainly talk about the DCL mode on the problem of instruction rearrangement, and reflection can destroy several ways except enumeration; the applications of singleton mode are: First, Spring Bean The scope of the default is to use the singleton mode; second, the ErrorContext class in Mybatis also uses the singleton mode, this class is used to record the error information of the thread execution environment)
    Reference article: https://blog.csdn.net/can_chen /article/details/105049999

  5. Decorator mode (application: The decorator mode is used for JAVA IO stream)
    Reference article: https://blog.csdn.net/can_chen/article/details/105786680

  6. The difference between decorator mode and proxy mode?
    Reference article: https://www.cnblogs.com/yanggb/p/10952843.html

  7. Strategy mode (Application: The sort method of the Arrays class uses the strategy mode. The Comparator interface is a strategy interface. The sort method is defined as a strategy. The user can customize the sorting strategy, which can be ascending or descending).
    Reference article: https ://blog.csdn.net/can_chen/article/details/106745298

  8. What is the difference between the observer model and the publish-subscribe model? (The JDK source code has provided us with a set of observer patterns. Observer is the observer interface, and the Observable class is the observable, which is a concrete class. It provides a collection of all observer roles and also provides for adding observations. , Remove observers, notify observers, etc.)
    Reference article: https://blog.csdn.net/hf872914334/article/details/88899326

Eight Network
  1. The TCP three-way handshake and four waved hands, the content of each packet sent, the status of the client and server?

  2. Can TCP three-way handshake carry data? The runtime phase of the TCP protocol?

  3. Why is it a three-way handshake, can it be a four-way handshake or two handshake?

  4. Why does it take three handshake and four wave hands?

  5. Why does TCP wave four times to wait for 2MSL in the TIME-WAIT phase? Which party has the TIME-WAIT phase? (Actively release the end that releases the connection)

  6. TCP long connection and short connection ( http://blog.sina.com.cn/s/blog_6d39b5be0101k6v4.html )

  7. Semi-connected queue and fully connected queue, what are syn flood attacks, and how to deal with syn flood attacks? ( Https://www.jianshu.com/p/ff26312e67a9 )

  8. What happens after I enter a URL in the browser and press Enter? ( https://www.cnblogs.com/tisikcci/p/5866753.html )

  9. Recursive query and iterative query during the domain name resolution process ( https://blog.csdn.net/weixin_42061048/article/details/80170991 )

  10. After the browser enters a URL, according to the TP/IP reference model, which protocols are used from the application layer to the network layer?

    (Application layer: HTTP, DNS; Transport layer: TCP, UDP; Network layer: IP, ICMP, ARP)

  11. Two applications of the ICMP protocol-Ping and Traceroute ( https://www.jianshu.com/p/32bc2749a831 )

  12. What is the difference between IP address and MAC address?

  13. The difference between http and https ( https://www.php.cn/faq/418162.html )

  14. Why do websites use cookies and sessions; what is the difference between cookies and sessions?

  15. The difference between get request and post request?

  16. The difference between TCP and UDP and their respective application scenarios?

  17. The difference between epoll and select?

Nine JVM
  1. JVM memory model (program counter, virtual machine stack, local method stack, heap, method area)

  2. What changes have been made in JDK1.8? (JDK1.7 has moved the string constant pool originally located in the permanent generation to the heap, but the concept of permanent generation still exists. JDK1.8 completely abolished the permanent generation and replaced it with metaspace)

  3. Permanent generation and metaspace, why should JDK1.8 use metaspace instead of permanent generation?

  4. Metaspace overflow? (Metaspace does not belong to the Java virtual machine. It uses local memory and stores some information of classes and methods. Dynamic loading of classes or frequent loading of class information, but not unloading in time will cause metaspace overflow)

  5. Two ways of object creation (pointer collision, free list), two ways of object access location (using handle, direct pointer)

  6. Allocation and escape analysis on the stack (Skills for Java performance optimization at the JVM level)

  7. Two ways to judge whether an object is alive, the disadvantages of reference counting? (Citation counting method, accessibility analysis method)

  8. About the finalize() method of the Object class (jvm is automatically executed, no need to manually call, it can only be executed once).

  9. Four types of references in java (strong reference, soft reference, weak reference, phantom reference)

  10. Three garbage collection algorithms, their advantages and disadvantages (mark-sweep method, mark-copy method, mark-sort method)

  11. The difference between Minor GC and Full GC, trigger conditions, and space allocation guarantee strategy?

  12. Memory overflow and memory leak (the accumulation of memory leaks will cause memory overflow)

  13. JVM parameter tuning (-Xms, -Xmx, -Xss, -XX:NewRatio, -XX:SurvivorRatio, -XX:+PrintGCDetails, -HeapDumpOnOutOfMemory)

  14. How to solve OOM (first try to expand the heap memory space through JVM parameter tuning; then dump the heap memory storage snapshot, use the JProfile tool for analysis)

  15. Garbage collector (CMS mostly asks, in addition, if you talk about the bad experience that gc will bring to users, you can talk about Stop the World)

  16. What kind of work is done in the preparation phase of the class loading mechanism? (The preparation phase will allocate memory (method area) to the static variables of the class and assign initial values. If the static variables of the class are modified by final, then the initialized value is not a zero value, but a declared value)

  17. The definition of the parent delegation model of the class, the benefits of the parent delegation model? How to break the parent delegation model of the class?

Ten operating system
  1. The difference between Linux zombie process and orphan process, how to clean up zombie process? (Kill the parent process of the zombie process)
  2. How to view zombie process information? How to count the number of zombie processes? (Ps-ef | grep defunct; ps -ef | grep defunct | wc-l)
  3. The difference between concurrency and parallelism?
  4. The difference between process and thread?
  5. What are the ways of process communication? (Pipe, message queue, shared memory, semaphore, socket Socket)

To be continued………………

Guess you like

Origin blog.csdn.net/can_chen/article/details/109285499