2019java interview

Interview basis

  1. Talk about the same hash algorithm?
    Hash algorithm according to the key corresponding to a hash space of 2 ^ ^ 32 having buckets, i.e. digital space of 0 to (2 ^ 32) -1. These figures will be connected end to end, imagine a closed ring. If the addition of a new cluster of machines using its unique IP alias or the hash value is calculated, also maps to the ring. New key value in a clockwise direction, stored in the nearest machine.
    Reference: https://blog.csdn.net/cb_lcl/article/details/81448570

  2. Talk about optimistic and pessimistic locking?
    Optimistic locking: Suppose someone does not modify the data for each operation, when the updated data to determine whether the version number changes depending less suitable for reading and writing scene.
    Pessimistic locking: Suppose someone else will modify the data for each operation, plus the first lock before the operation, the latter operation is blocked until the operation is completed to release the lock.

  3. Talk about the knowledge of MySQL, Oracle and distinction of?
    MySQL is an open source relational database that supports standard SQL language, supports multiple data engine, transactions, master-slave configuration. Internet is widely used in small and medium sized companies. And Oracle difference:
    • Positioning: Oracle is a large database, Mysql small and medium sized databases. Oracle is a paid commercial databases, MySQL is a free open source database.
    • Performance: Oracle stronger concurrent performance, richer data management tools.
  4. Talk about the four characteristics of affairs?
    • A (atomicity): the transaction is an indivisible unit of work operations in a transaction either occur or do not occur.
    • C (consistency): the integrity of the data before and after the transaction must be consistent and logical operations.
    • I (isolation): when a plurality of users concurrent access to the database, the user opens a database for each transaction, the operation data can not be disturbed by other transactions, for isolation between a plurality of concurrent transactions.
    • D (persistence): Once the transaction is committed, it changed data is permanent, even if the database failure should not affect them.
  5. Talk about the affairs of the two-phase commit mechanism?
    Distributed transaction has two roles: the transaction coordinator and participants in the transaction, two-phase commit protocol to coordinate all transaction participants decided to submit or cancel (rollback) way.
    1. prepare stage: the coordinator asks whether each participant performed normally, inform the participants ready to commit the transaction or cancel the transaction, and then enter the voting process. In the voting process, participants will inform the coordinator of its decision: consent (transaction participants local job execution success) or cancel (local job execution fault).
    2. commit phases: the coordinator utilizing the results of the preparatory phase of the decisions, if and only if all participants agree to commit the transaction coordinator before notifying all participants to commit the transaction, or coordinator will notify all participants cancel the transaction
  6. Talk about the principles of database indexes, clustered indexes and non-clustered index?
    Is a data structure (algorithm storage structure +) essentially on the index, the purpose is to accelerate the speed of data retrieval.
    https://www.jianshu.com/p/e1dce41a6b2b

  7. For example about index usage scenarios?
    • Primary key index: set the primary key to the table, this table will have a primary key index.
    • General index: the index of an increase in the field, such as user-table query based on the user name.
    • Composite index: the index increased more than one field, follow the leftmost principles, such as creating an index (col1 + col2 + col3), the equivalent of creating (col1), (col1, col2), (col, col2, col3) three indexes.
  8. Read and talk about the current database snapshot read?
    • Snapshots read: simple selectsnapshot read.
    • Current Reading: select for update,insert,update,delete the current reading.
    • Principle: In the repeat read level, the snapshot is read by MVVC (multi-version control) and undo log to achieve, the current reading is accomplished by adding record lock (record locking) and gap lock (lock gap) to achieve.
  9. HashTable & HashMap & ConcurrentHashMap differences, advantages and disadvantages?
    Compared to HashMap, HashTable and ConcurrentHashMap are thread safe. HashTable in the put and get together synchronize synchronization control. ConcurrentHashMap by the segment lock, prevent full lock hash table, to improve the efficiency of synchronization.
    Reference: https://www.cnblogs.com/sunshinekevin/p/10625516.html

  10. Synchronize is reentrant lock on it, realization of the principle?
    Reentrant lock,
    reference: https://blog.csdn.net/zc19921215/article/details/84780335

  11. Talk about the JVM class loading process?
    Load (Loading), verification (Verification), preparation (Preparation), analytical (Resolution), initializing (Initialization), using (Using) and unloading (Unloading) 7 stages.
    Loading: Find the file and import Class.
    Links: The merger of binary data type to the JRE.
    Check: Check the correctness of Class load file data.
    Preparation: static variables to the class of allocating storage space.
    Analysis: reference symbol turn into direct reference.
    Initialization:, static code block executes initialization static class variable.

  12. JVM parents appointed mechanisms and the use of reason?
    • Mechanism: The task of the current class load transferred to its parent class loader, if its parent class has a parent class, they continue to pass up, if the parent class loader fails to load it.
    • Meaning: to avoid duplication and to modify the risk of load core classes.
  13. Talk about Java's GC mechanism, which has several GC algorithms?
    C / C ++ applications to be called when the system malloc memory, after use by the release of free memory. Java virtual machine is assigned to a large space-time, and then automatically released and allocated in the space, the programmer need not manually under normal circumstances. GC automatic recovery mechanism is to solve, face three problems: how to determine the garbage, garbage how, when recovered.
    • How to determine the trash:
      • Reference counting algorithm: add a reference to the object counter, when there is a reference to its place, the counter value is incremented by 1; when referring to the failure, the counter value is decreased by 1; any time counter for the object 0 is death. Reference counting algorithm is very simple, to judge the efficiency is also high, but the JVM did not choose it to manage memory. what is the reason? Mainly because it is difficult to solve the problem of circular references.
      • Reachability analysis algorithm: Through a series of objects called GC Roots as a starting point, to start the search down from these nodes, searching through all the paths known as the "chain of references", when an object has no references to GC Roots chain when connected, the proof of this object is unavailable.
    • How garbage:
      • Generational collection method: It is based on the life cycle of the object, the heap into the new generation and the old era. In the new generation, because of the short lifetime of the object, there will be a large number of objects recovered each time to die, then the time on the use of replication algorithm. The old era of objects higher survival rates, there is no extra space is allocated guarantee, so you can use tags to organize or mark cleared.
      • Clear labeling law: the need to recycle objects flagged bulk removal. The disadvantage is low efficiency, resulting debris.
      • Mark arranging method: The marked objects need to be recovered, and then moved to one end cleared, avoiding the generation of debris.
      • Copy method: the new generation memory is divided into 8: 1: 1 into three parts, a larger area called Eden, and the remaining two are smaller Survior area. Eden precedence every time zone, if the Eden area is full, the object will be copied to the second memory block area, and then clear the Eden area, this time surviving if too many objects, so that when Survivor is not enough, these objects will pass guarantee mechanism for distributing copies to the old era.
    • When recovery:
      GC There are two types: Scavenge GC and Full GC.
      • Scavenge GC: In general, when a new object is generated, and upon failure of Eden space applications, will trigger Scavenge GC, the GC area of ​​Eden, remove non-live objects, and the object moving to yet survive Survivor areas. Then come up with two zones of Survivor. GC this way for younger generations of Eden zone, will not affect the old generation. Because most of the objects are from the beginning of the Eden area, while the Eden area does not allocate large, so the GC Eden area occur frequently. Thus, in general use here need fast speed, high efficiency of the algorithm, the Eden to be able to free up as soon as possible.
      • Full GC: to collate the entire stack, including Young, Tenured and Perm. Full GC because of the need to recover the entire heap, so slower than Scavenge GC, and should therefore reduce the number of Full GC as possible. In the process of tuning the JVM, a large part of the work is adjusted to the Full GC. The following reasons may lead to Full GC:
        • Old generation (Tenured) is filled
        • Permanent generation (Perm) is written
        • System.gc () call is displayed
        • The last time the dynamic allocation strategy changes each domain after the GC Heap
      Reference: https://blog.csdn.net/u011983531/article/details/79479972
  14. Talk about the core thread pool parameters and rationale, tuning strategy?
    • The core argument:
      corePoolSize: the number of kernel threads in the thread pool.
      maximumPoolSize: thread pool while allowing the maximum number of threads exist.
      RejectedExecutionHandler: denial of service policy.
      keepAliveTime: When the work is greater than the number of threads in the thread pool corePoolSize, and the thread is idle for more than keepAliveTime, these threads will be terminated.
    • Rationale:
      Reference: https://www.jianshu.com/p/896b8e18501b
    • Tuning Strategy
      To a reasonable allocation of the thread pool, you must first analyze characteristics of the task to be analyzed from several perspectives:
      the nature of the task: CPU-intensive tasks, IO-intensive tasks and mixed tasks.
      Priority tasks: high, medium and low.
      Execution time of the task: long, medium and short.
      Dependent tasks: whether to rely on other system resources, such as database connections.
      Reference: https://blog.csdn.net/chenpeng19910926/article/details/78142187
  15. Collections.sort underlying sort? Sorting stability? Ordering policy specific scene?
    The algorithms are TimSort Collections.sort Arrays.sort and end-use.
    Timsort core processes:
    1, less than 32 when the number of the array using the binary insertion sort.
    2, the array 32 is greater than first calculating a suitable size, is partitioned according to their ascending and descending input characteristics. Enter the sort is not a separate number, but a number of blocks - partition. In which each partition is called a run. For these run sequences, a time to get a run out of the merger by the rules. Each integration will run two merged into a run. Save the merged result to the stack. The combined run until all consumed, the time remaining on the stack to run only a combined run so far. Then this is the only remaining run good result row sequence.
    3, Timsort algorithm is stable, when the array to be sorted have been sorted in number, it will be less than the time complexity nlogn. Like other merge sort, Timesort sorting algorithm is stable, the worst time complexity is O (n log n). In the worst case, the algorithm requires temporary space Timsort is n / 2, in the best case, requires only a small temporary storage space

  16. Frequent old's recovery analysis of how to solve?
    Reference:
    https://www.cnblogs.com/justdojava/p/11198106.html
    http://www.codersui.com/198.html
    younger generation went through the N-th garbage objects recovered still alive and will be put the old generation, the old filled years after triggering FULL GC, there is generally an object can not be recycled can lead to frequent old's recovery, troubleshooting steps are as follows:
    1. ps command to get pid:ps -ef|grep your_application
    2. jstat command to query gc situation:jstat -gcutil 172046 1000
    3. Jmap analysis using object's memory footprint case, and export them to jmap.txt in: jmap -histo 172046 > jmap.txt
  17. Talk about the principle of Spring IOC, AOP's?
    • IOC is inverted control means for reducing the coupling between the tags. Sublimation factory mode, the IOC can be seen as a container factory, the factory object to be produced are given in the definition of the configuration file, and then using a programming language programming reflection, according to the generated class name given profile the corresponding object. (A process of obtaining the object of dependent objects B, by the active behavior becomes a passive behavior, control over reversed, this is the "inversion of control" the origin of the name).
    • AOP Aspect Oriented Programming meaning, agent-based thinking. Create a proxy object to the original target object, without modifying the original object code, add code enhancements through a proxy object, which enhanced the original business methods. JDK dynamic proxy implementations have bytecode Cglib and dynamic techniques.
  18. Java blocking queue do not provide their own realization of how, condition and can not wait?
    Https://blog.csdn.net/h525483481/article/details/80347485

  19. Congestion window Why the slow start?
    Https://www.cnblogs.com/losbyday/p/5847041.html

  20. There are several load balancing algorithms to talk about the advantages and disadvantages?
    • Polling
      all requests are sequentially distributed to each server, the server hardware for the same scene.
      Advantages: the server requesting the number of identical
      disadvantages: the pressure is not the same server, the server is not configured for different situations
    • Random
      requests randomly assigned to each server.
      Advantages: simple
      drawback: not suitable machine configuration different scenarios
    • Minimum link
      to request allocation of the minimum number of connections to the server (server currently handling the least requests).
      Advantages: dynamically allocated according to the current server request handling of
      disadvantages: relatively complex algorithms, the server needs to monitor connection requests
    • Hash (source address hash)
      for Hash calculated based on IP address, to obtain the IP address.
      Pros: The request from the same IP address, during the same session, forwarded to the same server to achieve session sticky
      Cons: target server goes down, the session will be lost
    • Weighted
      polling, random, at least a link, based on the Hash algorithm, etc., by a weighted manner, the server load distribution.
      Advantages: The weight adjustment of the number of requests forwarding server
      drawbacks: the use of relatively complicated
  21. Redis data consistency problems (distributed multi-node environment & stand-alone environment)
    https://blog.csdn.net/qq_27384769/article/details/79499373

  22. Brief docker container?
    Docker is a container platform, it will be packaged in the form of a container with your application and all of its dependencies, to ensure that your applications run seamlessly in any environment.

  23. Perception and cognition design patterns, what are design patterns?
    Is a set of design patterns are used repeatedly, summed up the experience of code design known to most people. Common design patterns are as follows:
    the factory mode: the Spring factory mode by creating bean
    proxy mode: Spring AOP enhancements to the original object by dynamic agent
    Chain of Responsibility pattern: SPRINGMVC filter
    Singleton: default objects is a single spring embodiment constructed

  24. How to implement a distributed cache?
    Distributed Cache system to meet the dynamic expansion and high availability, usually Redis implementation. Sentinel Master-slave mode,
    Cluster model for clustering. By doing consistent hashing key, key distribution corresponding to achieve redis node.

  25. Multithreading how to avoid a deadlock?
    • Locking sequence (thread locking in a certain order)
    • Locking time (when the thread tries to acquire a lock with a certain time limit, exceeding the time limit for the lock request is discarded, and the release of their possession of the lock)
    • Deadlock Detection (jstack -l jvm_pid)
  26. Runtime briefly on the JVM?
    Runtime class represents the Java Runtime Environment program, each program has a Java Runtime instance, the class is automatically created, you can get Runtime instance of the current program by Runtime.getRuntime () method.

  27. DNS resolution process?
    1. Queries the local hosts file
    2. The query DNS cache
    3. Query the local DNS server
    4. Local DNS server forwards the request to the root server DNS
      Reference: https://www.jianshu.com/p/401f34691dcc
  28. Brief Htttp agreement, the difference Http and Https, Https encryption method?
    HTTP is used to transfer a data (HTML files, images, etc.) based on TCP / IP communication protocol, which belongs to the client - server mode, the browser sends a request to the WEB server as a client through the HTTP URL. https is added between http and TCP SSL layer, it is to prevent fishing and data encryption. HTTPS using an asymmetric encryption algorithm negotiated symmetric encryption algorithm, the processing steps are as follows:
    1. The server will carry the public key to the digital certificate authority to request a certificate.
    2. Digital certificate authority issued the certificate with its private key to the public key signature, and returned to the server.
    3. The server application to carry a certificate of public key distribution to customer service side.
    4. Client authentication certificate, the certificate authority verified, or user acceptance certificate (non-certificate issued by the authority) untrusted. To obtain the public key. At this point in the certificate to ensure that the server has a private key, the client has the public key can be asymmetric encryption.
    5. Using public-key encrypted message is sent to the server, which carries a random string. Wherein the symmetric encryption of the user data transmission random string.
    6. The server uses the private key to decrypt. Get the message information and random strings.
    7. After decryption server sends a handshake message to the client.
    8. The client accepts handshake message, the end of the handshake, the two sides determine the encryption algorithm (symmetric encryption using a random string determined), start the transfer.
    9. Data transmission using symmetric encryption algorithm.
  29. Http request process?
    1. DNS name resolution on the URL to obtain the corresponding IP address.
    2. Find the corresponding server based on IP, TCP three-way handshake initiated.
    3. After establishing a TCP connection to initiate HTTP requests.
    4. HTTP server responds to the request, the browser obtained html code.
    5. Browser parses the html code, html request contains an address other resources (such as js, css pictures, etc.).
    6. Browser page rendering to the user.
  30. TCP three-way handshake protocol to talk about the four wave?
  • Three-way handshake:
    1. The first handshake: Client SYN flag bit is set to 1, a randomly generated value seq = J, and the packet is sent to the Server, Client enters the SYN_SENT state, waiting for acknowledgment Server.
    2. Second handshake: Server receives the packet data from the flag bit SYN = 1 know Client requests to establish a connection, Server SYN and ACK flag bit are set to 1, ack (number) = J + 1, a randomly generated value seq = K, and transmits the data packet to acknowledge a connection request to the Client, Server enters SYN_RCVD state.
    3. Third handshake: the Client receives acknowledgment, checking whether the ack J + 1, ACK is 1, then if the correct ACK flag is set to 1, ack = K + 1, and the packet is sent to the Server, Server checks whether the ack K + 1, ACK is 1, if correct, the connection is established, Client and Server enters eSTABLISHED state, complete the three-way handshake, then you can begin to transfer data between Client and Server.
  • Four wave:
    1. The first wave: Client sends a FIN, for closing the data transfer Client Server tenderer, Client enters FIN_WAIT_1 state.
    2. Second wave: Server receives the FIN, ACK to send a Client, the acknowledgment number for the receipt number +1 (the same SYN, FIN a occupy a sequence number), Server enters CLOSE_WAIT state.
    3. Third Wave: Server sends a FIN, for closing the Client Server data transfer, LAST_ACK Server enters state.
    4. The fourth wave: the Client receives the FIN, Client enters TIME_WAIT state, and then sends an ACK to the Server, for the receipt of the acknowledgment number number + 1, Server enters the CLOSED state, four complete wave.
    Reference: https://www.cnblogs.com/lms0755/p/9053119.html

Project Experience

  1. The greatest impact of a project for you?
  2. Talk about where their participation in the project technical difficulty? Which part of the most difficult to overcome? How to overcome?
  3. Why you would want to do this project? idea of ​​this project is proposed by who?
  4. To talk about the project used in understanding middleware (Dubbo, MQ, Redis, kafka, zookeeper)?
  5. Server avalanche is caused by how? Before you have such experience? How to prepare?
  6. Talk about high concurrent architecture design ideas?
    • CDN caching static resources
    • Split and load balancing services
    • Distributed Cache
    • Decoupling traffic message queue clipping
    • Database clustering and database hash table.
  7. How to implement large projects in data transfer and storage?
  8. How to achieve under the clipping and limiting how high concurrency?
    Limiting algorithm: leaky bucket algorithm and the token bucket algorithm (based Distributed token bucket Redis)

  9. Outlined the benefits of modular software?
    • Encourages code reuse
    • In favor of division of labor
    • In favor of modular test
    • In favor of modular deployment and monitoring, troubleshooting

Life experience

    1. The biggest setbacks encountered in daily life, how to solve?
    2. The most rewarding things in life experience?
    3. What are your career planning?

Guess you like

Origin www.cnblogs.com/gm123/p/11549237.html