2021 latest compilation of Java interviews (1000 answers with analysis)

The gold three silver four half of 2021 is about to pass. I summarized all kinds of Java interview questions in the first half of the year, including Java basics, JVM knowledge interview question bank, open source framework interview question bank, operating system interview question bank, and more Threaded interview question bank, Tcp interview question bank, architecture design and distributed interview question bank, algorithm interview question bank, database interview question bank, message queue interview question bank, cached interview question bank;

å²ä¸æå¨499éJavaé ¢ è¯é ¢ ï¼JVM + åå¸å¼ + ç®æ³ + é + MQ + å¾®æå¡ + æ ° æ®åº

JAVA basics

  1. What are the several basic data types in JAVA, and how many bytes each occupies.
  2. Can the String class be inherited and why.
  3. The difference between String, Stringbuffer, StringBuilder.
  4. What is the difference between ArrayList and LinkedList.
  5. Talk about the instantiation order of the class, such as the parent class static data, constructor, field, subclass static data, constructor, field, when new, their execution order.
  6. Which Map classes have been used, are there any differences, is HashMap thread-safe, what Map is used concurrently, and what are their internal principles, such as storage method, hashcode, capacity expansion, default capacity, etc.
  7. Why did JAVA8's ConcurrentHashMap give up the segment lock? Is there any problem? If you design it, how do you design it.
  8. Are there any Map implementation classes in order, and if so, how do they ensure ordering?
  9. The difference between abstract class and interface, can a class inherit multiple classes, can an interface inherit multiple interfaces, and can a class implement multiple interfaces?
  10. What is the difference between inheritance and aggregation.
  11. What are the IO models, talk about the nio you understand, what is the difference between him and bio, aio, talk about the reactor model.
  12. The principle of reflection, what are the three ways that reflection creates a class instance.
  13. In reflection, the difference between Class.forName and ClassLoader.
  14. Describe several implementations of dynamic agents, and state their respective advantages and disadvantages.
  15. The difference between dynamic proxy and cglib implementation.
  16. Why the CGlib method can implement proxy for the interface.
  17. The purpose of final.
  18. Write three singleton mode implementations.
  19. How to automatically complete all hashcode and equals implementations for subclasses in the parent class? What are the pros and cons of doing this.
  20. Please talk about the role of access modifiers public, private, protected, and default in application design based on the OO design concept.
  21. The difference between deep copy and shallow copy.
  22. Array and linked list data structure description, their respective time complexity.
  23. The difference between error and exception, CheckedException, RuntimeException.
  24. Please list 5 runtime exceptions.
  25. In your own code, if you create a java.lang.String class, can this class be loaded by the class loader? why.
  26. Tell me about your understanding of the hashCode and equals methods in the java.lang.Object object. In what scenario
  27. To re-implement these two methods.
  28. In jdk1.5, generics are introduced, and the existence of generics is used to solve problems.
  29. What is the use of such a.hashcode() and what does it have to do with a.equals(b).
  30. Is it possible that two unequal objects have the same hashcode.
  31. How does HashSet in Java work internally.
  32. What is serialization, how to serialize, why serialization, what problems will be encountered in deserialization, and how to solve them.
  33. New features of java8.

JVM knowledge

  1. Under what circumstances will stack memory overflow occur.
  2. JVM memory structure, Eden and Survivor ratio.
  3. Why should JVM memory be divided into the new generation, the old generation, and the persistent generation. Why is the new generation divided into Eden and Survivor.
  4. What is a complete GC process in the JVM, how to promote the object to the old age, talk about the main JVM parameters you know
  5. number.
  6. Do you know which kinds of garbage collectors, their advantages and disadvantages, focus on cms and G1, including principles, processes, advantages and disadvantages.
  7. The realization principle of garbage collection algorithm.
  8. When there is a memory overflow, how do you troubleshoot?
  9. How much do you know about the relevant knowledge of the JVM memory model, such as reordering, memory barriers, happen-before, main memory, work
  10. Memory, etc.
  11. Simply talk about the class loader you know, can it break parental delegation, and how to break it.
  12. Talk about the reflection mechanism of JAVA.
  13. What are the JVM parameters of your online application?
  14. The difference between g1 and cms is the garbage collector choice of throughput priority and response priority.
  15. How to print thread stack information.
  16. Please explain the meaning of the following jvm parameters:
  17. -server -Xms512m -Xmx512m -Xss1024K
  18. -XX:PermSize=256m -XX:MaxPermSize=512m -
  19. XX:MaxTenuringThreshold=20XX:CMSInitiatingOccupancyFraction=80 -
  20. XX:+UseCMSInitiatingOccupancyOnly。

Open source framework knowledge

  1. Briefly talk about the structure of tomcat, its class loader process, thread model, etc.
  2. How to tune tomcat and what parameters are involved.
  3. Talk about the Spring loading process.
  4. The realization principle of Spring AOP.
  5. Talk about the propagation properties of Spring transactions.
  6. How does Spring manage transactions.
  7. How does Spring configure transactions (specifically say some key xml elements).
  8. Tell me about your understanding of Spring, the principle of non-singleton injection? Its life cycle? The principle of cyclic injection, the realization principle of aop
  9. Reason, talk about a few terms in aop, how they work with each other.
  10. The initialization process of DispatcherServlet in Springmvc.
  11. Netty's threading model, how netty is based on the reactor model.
  12. Why choose netty.
  13. What is TCP sticky packet and unpacking. What is the solution.
  14. Netty's fashwheeltimer usage, implementation principle, whether the call is not punctual, and how to solve it.
  15. What about netty's heartbeat processing in a weak network?
  16. What is the communication protocol of netty.
  17. The annotations used by springmvc, what are their functions, and their principles.
  18. Springboot startup mechanism.
  19. Click here for a set of Spring test questions with answers.

operating system

  1. What kernel parameters have you paid attention to under Linux, tell me what you know.
  2. There are several IO models under Linux, and what are their meanings.
  3. What is the difference between epoll and poll.
  4. What Linux commands are usually used.
  5. Use a one-line command to view the last five lines of the file.
  6. Output the running java process with one line command.
  7. Introduce the thread switching process in the operating system you understand.
  8. The difference between process and thread.
  9. What's after the top command and what's the effect.
  10. Online CPU is bursting high, how do you find the problem?

Multithreading

  1. Several implementations of multithreading, what is thread safety.
  2. The principle and function of volatile can replace locks.
  3. Draw the life cycle state diagram of a thread.
  4. The difference between sleep and wait.
  5. The difference between sleep and sleep(0).
  6. The difference between Lock and Synchronized.
  7. What is the principle of synchronized and where is it generally used (for example, the difference between static and non-static methods, static
  8. State method and non-static method will have an impact when executed at the same time), explain the following terms: reordering, spin lock, biased lock, light
  9. Magnitude locks, reentrant locks, fair locks, unfair locks, optimistic locks, and pessimistic locks.
  10. Which atomic classes have been used, and what are their principles.
  11. Which concurrency tools have been studied under JUC, and talk about the principles.
  12. Have you ever used the thread pool? If you have used it, please explain the principle, and talk about the difference between newCache and newFixed, the construction letter
  13. What is the meaning of the various parameters of the number, such as coreSize, maxsize, etc.
  14. There are several ways to close the thread pool, and what is the difference between them.
  15. If there is a third-party interface, there are many threads to call to obtain data, now it is stipulated that there are at most 10 threads at the same time per second.
  16. When to call it, how to do it.
  17. Whether the spring controller is singleton or multiple instances, how to ensure the safety of concurrency.
  18. Use three threads to print the three letters of abc in sequence, such as abcabcabc.
  19. Have you ever used ThreadLocal, what is its purpose, its principle, and what should be paid attention to when using it.
  20. If you let you implement a concurrency-safe linked list, what would you do?
  21. What are the lock-free data structures, and what are the principles of their implementation.
  22. Talk about wait and notify of java synchronization mechanism.
  23. What is the CAS mechanism and how to solve the ABA problem.
  24. What if a thread hangs in multithreading.
  25. The internal principles and usage of countdowlatch and cyclicbarrier, and the differences between each other (such as
  26. The await method of countdownlatch and how it is implemented).
  27. How much do you know about AbstractQueuedSynchronizer, talk about the process of locking and unlocking, exclusive locks and fairness
  28. What's the difference with locking.
  29. What is the difference between using synchronized to modify static methods and non-static methods.
  30. Briefly describe the use and difference between ConcurrentLinkedQueue and LinkedBlockingQueue.
  31. What causes thread deadlock? How to release thread deadlock.
  32. Many threads (maybe different machines) need to wait for coordination between each other to complete a certain kind of work. Ask how to design this coordination scheme.
  33. Have you ever used a read-write lock, what is the principle, and in what scenarios?
  34. Open multiple threads, if the order of execution is guaranteed, what are the ways to achieve it, or how to ensure that multiple threads are executed
  35. Get the result again.
  36. The implementation of the delay queue, the similarities and differences between the delayQueue and the time round algorithm.
  37. Click here to have a set of multi-threaded test questions with answers.

TCP与HTTP

  1. What is the difference between http1.0 and http1.1.
  2. For the TCP three-way handshake and four waved hands, why does the disconnection take 4 times? If there are only two handshakes, what will happen.
  3. The difference between TIME_WAIT and CLOSE_WAIT.
  4. Talk about several HTTP response codes you know, such as 200, 302, 404.
  5. When you use a browser to open a link (such as: http://www.javastack.cn), what steps the computer does?
  6. How to ensure the reliability of TCP/IP, talk about the structure of the TCP header.
  7. How to avoid browser caching.
  8. How to understand the statelessness of the HTTP protocol.
  9. Briefly describe the difference between Http request get and post and the data packet format.
  10. What are the HTTP methods
  11. Briefly describe the message format of the HTTP request.
  12. What does HTTP long connection mean.
  13. What is the encryption method of HTTPS? Let's talk about the entire encryption and decryption process.
  14. What is the difference between the three-way handshake between Http and https.
  15. What is block transfer.
  16. The difference between Session and cookie.
  17. Click here to have an answer version of the test questions.

Architecture design and distributed

  1. Implement an LRU by yourself in java.
  2. How to achieve a unique serial number in a distributed cluster.
  3. Design a spike system that automatically closes the transaction without paying for 30 minutes.
  4. How to use redis and zookeeper to implement distributed locks? What is the difference between the advantages and disadvantages, what problems will there be, and what are applicable
  5. Scenes. (Extension: If you know redlock, talk about his algorithm implementation, where is the controversy)
  6. If someone maliciously creates an illegal connection, how to solve it.
  7. Principles of distributed transactions, advantages and disadvantages, how to use distributed transactions, the difference between 2pc and 3pc, what problems are solved, and
  8. What problems are not solved, how to solve them, and how are distributed transactions involved in your own project handled.
  9. What is a consistent hash.
  10. What is restful, talk about restful as you understand it.
  11. How to design a good API.
  12. How to design to establish and maintain a 100w long connection.
  13. Explain what is the MESI protocol (cache coherency).
  14. Talk about several HASH algorithms you know, simple ones are fine.
  15. What is the paxos algorithm and what is the zab protocol.
  16. An online document system, the document can be edited, how to prevent multiple people at the same time
  17. Edit and update a document.
  18. The online system suddenly becomes abnormally slow, how do you find the problem.
  19. Talk about the design patterns you usually use.
  20. The principle of Dubbo, have you seen the source code, how the data flows, how to implement clustering, load balancing, service registration
  21. And discover, retry forwarding, what is the fast failure strategy.
  22. What is the flow of an RPC request.
  23. Have you implemented rpc by yourself? The principle can be explained briefly. What problem does Rpc want to solve.
  24. The purpose and meaning of asynchronous mode.
  25. In programming, how do I consider some design principles, such as the opening and closing principles, and the application in work.
  26. Design a "private message" function in a social networking site, which requires high concurrency, scalability, and so on. Draw an architecture diagram.
  27. The MVC pattern is a common MVC framework.
  28. Let's talk about the server architecture that we have participated in the design and draw a picture, and talk about the problems we encountered and how to solve them.
  29. How the application server monitors performance, the difference in various ways.
  30. How to design a high-concurrency payment scheme and how to design the architecture.
  31. How to achieve load balancing and what algorithms can be implemented.
  32. What is the purpose of Zookeeper and the principle of election.
  33. The principle of Zookeeper watch mechanism.
  34. The underlying implementation principle of Mybatis.
  35. Please consider a scheme to implement countDownLatch in a distributed environment.
  36. How does the background system prevent repeated requests from being submitted.
  37. Describe the detailed process of a service from being published to being consumed.
  38. Talk about service governance that you understand.
  39. How to achieve the idempotence of the interface.
  40. How to do the current limiting strategy, the usage scenarios of the token bucket and the funnel algorithm.
  41. What is data consistency, and how do you understand data consistency.
  42. If the distributed service caller does not rely on the service provider, how to deal with a large number of invalid resource requests after the service provider hangs up
  43. What to do if the service provider’s throughput is not high? If the service is down, it will restart in a while, what should I do?
  44. What is the mechanism to achieve the minimum waste of resources?
  45. How did dubbo's generalization call be implemented, and if it were you, how would you do it.
  46. Remote calls will have timeouts. If you can achieve elegant control, what are the timeout mechanisms that come with the JDK and how to implement them.

algorithm

  1. Find the smallest 10 out of a billion numbers.
  2. There are 100 million numbers, of which 2 are repeated, find it quickly, time and space should be optimal.
  3. 200 million randomly generated unordered integers, find the value of the middle size.
  4. For an input string of unknown length (which may be very large), design a scheme to sort repeated characters.
  5. Traverse the binary tree.
  6. There are 3n+1 numbers, of which 3n are repeated, and only 1 is not repeated. How to find out.
  7. Write a string (such as: www.javastack.cn) to reverse the function.
  8. Commonly used sorting algorithms, fast sorting, merging, and bubbling. The optimal time complexity of fast sorting, the worst complexity. Bubble sorted
  9. Optimization.
  10. The time complexity and advantages of binary search.
  11. How to complete the reverse sorting of a built TreeSet.
  12. What is B+ tree, B-tree, list the actual usage scenarios.
  13. A singly linked list, delete the Nth data from the bottom.
  14. 200 ordered arrays, with 100 elements in each array, find the top20 element.
  15. Singly linked list, find the element in the middle.

Database knowledge

  1. What are the database isolation levels, what are their meanings, and what is the default isolation level of MYSQL.
  2. What is a phantom reading.
  3. What storage engines does MYSQL have, and their advantages and disadvantages.
  4. How to safely modify the same row of data under high concurrency.
  5. What are optimistic locks and pessimistic locks? What are the two types of INNODB's standard row-level locks? Explain their meanings.
  6. What are the general steps of SQL optimization, how to look at the execution plan, and how to understand the meaning of each field.
  7. Will the database deadlock? Give an example of deadlock, how does mysql solve the deadlock.
  8. MYsql index principle, what are the types of indexes, how to create reasonable indexes, and how to optimize indexes.
  9. The difference between a clustered index and a non-clustered index.
  10. What is the meaning of select for update, whether to lock the table or the row or other.
  11. Why is it implemented with Btree, how does it split, when does it split, and why is it balanced.
  12. What is the ACID of the database.
  13. There are nearly 10 million data in a table, CRUD is slow, how to optimize it.
  14. How does Mysql optimize table scan.
  15. How to write SQL can effectively use the composite index.
  16. The difference between in and exists in mysql.
  17. Possible problems with the database auto-incrementing the primary key.
  18. The meaning of MVCC, how to achieve it.
  19. Did you encounter sub-database and sub-table in the projects you have done? How did you do it, did you use middleware, such as sharding jdbc, etc.?
  20. Do you know the principle?
  21. How to solve the master-slave delay of MYSQL.

message queue

  1. Use scenarios of message queues.
  2. Retransmission of messages, supplementary strategies.
  3. How to ensure the orderliness of the message.
  4. Which MQs have you used? What are the advantages and disadvantages compared with other mqs? Is the connection of MQ thread safe? Your company's MQ service
  5. What is the structure.
  6. How to ensure that the data of the MQ system will not be lost.
  7. How rabbitmq achieves cluster high availability.
  8. The reason for the high throughput of Kafka.
  9. The difference between kafka and other message queues, how to realize the master-slave synchronization of kafka.
  10. How to use mq to achieve ultimate consistency.
  11. Are there any problems encountered when using Kafka and how to solve them.
  12. MQ may have repeated consumption, how to avoid it, and how to be idempotent.
  13. How to deal with MQ messages that are delayed? Can you set an expiration time for messages? How do you deal with them when they expire?

Cache

  1. What are the common caching strategies, how to achieve the consistency of the data in the cache (such as redis) and the DB, which are used in your project
  2. What cache system and how was it designed.
  3. How to prevent cache breakdown and avalanche.
  4. How to design the update after the cached data expires.
  5. Operations related to the redis list structure.
  6. What are the data structures of Redis.
  7. What to pay attention to when using Redis, talk about persistence methods, memory settings, cluster applications and advantages and disadvantages, elimination strategies, etc.
  8. The difference between redis2 and redis3, redis3 internal communication mechanism.
  9. What are the current redis cluster gameplay, their advantages and disadvantages, and scenarios.
  10. The principle of Memcache, which data is suitable to be placed in the cache.
  11. The difference between redis and memcached memory management.
  12. How to solve the problem of concurrent competition in Redis? Do you understand the CAS operation of Redis transactions?
  13. What is Redis's election algorithm and process?
  14. The persistence mechanism of redis, the difference between AOF and RDB.
  15. How does the redis cluster synchronize data.
  16. Know which redis optimized operations.
  17. Principle of Reids' master-slave replication mechanism.
  18. What is the threading model of Redis.
  19. Please think about a plan, design an automatically adaptive local cache that can control the overall size of the cache.
  20. How to treat the use of cache (local cache, centralized cache), briefly describe the advantages and disadvantages of local cache and centralized cache.
  21. Precautions for concurrent use of local cache.

search for

  1. How much does elasticsearch know, talk about your company's es cluster architecture, index data size, how many shards, and some
  2. Tuning means. What is the inverted index of elasticsearch.
  3. What to do if there is too much data in elasticsearch index, how to tune and deploy.
  4. How elasticsearch implements master election.
  5. Describe in detail the process of Elasticsearch indexing documents.
  6. Describe the process of Elasticsearch search in detail.
  7. When Elasticsearch is deployed, what are the optimization methods for Linux settings?
  8. What is the internal structure of lucence.

The above are the most comprehensive Java interview questions summarized, and the following are the latest BAT interview java required questions and answers.

2021 latest BAT advanced java interview questions and answers

The most complete 499 Java interview questions in history: JVM+distributed+algorithm+lock+MQ+microservice+database

The most complete 499 Java interview questions in history: JVM+distributed+algorithm+lock+MQ+microservice+database

 

How to get:

Just click on the portal ! !

The important thing is said three times. After forwarding, forwarding, and forwarding, click the portal to get it!

Guess you like

Origin blog.csdn.net/Java6888/article/details/115215968