JAVA advanced must-see directory

Overview of JAVA Interview Questions

1. 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 and 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. What are the differences between which Map classes have been used? Is HashMap thread-safe? What is the Map used concurrently? 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 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. Under what circumstances need to re-implement these two methods.
27. In jdk1.5, generics are introduced, and the existence of generics is used to solve problems.
28. What is the use of such a.hashcode() and what is the relationship with a.equals(b)?
29. Is it possible that two unequal objects have the same hashcode.
30. How does HashSet in Java work internally.
31. What is serialization, how to serialize, why serialization, what problems will be encountered in deserialization, and how to solve them.
32. New features of java8.


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


3. Open source framework knowledge
1. Briefly talk about tomcat structure, 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 (specify 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, talk about several terms in aop, how they work with each other.
9. The initialization process of DispatcherServlet in Springmvc.
10. Netty's threading model, how netty is based on the reactor model.
11. Why choose netty.
12. What is TCP sticky packet and unpacking. What is the solution.
13. The usage and realization principle of netty's fashwheeltimer, whether the call is not punctual, and how to solve it.
14. What to do with netty's heartbeat processing in a weak network.
15. What is the communication protocol of netty?
16. The annotations used by springmvc, what are their functions, and their principles.
17. Springboot startup mechanism.

 

4. Operating system
1. What kernel parameters have you paid attention to under Linux system, 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. Use one line of command to output the running java process.
7. Introduce the thread switching process in the operating system that you understand.
8. The difference between process and thread.
9. What are the contents after the top command and what are the effects.
10. The online CPU is bursting high, how do you find the problem?

 

5. Multithreading
1. Several implementations of multithreading, what is thread safety.
2. The principle and function of volatile, can it 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 (such as adding to the difference between a static method and a non-static method, will it affect when the static method and the non-static method are executed at the same time), explain the following terms: reordering, self Spin locks, partial locks, lightweight locks, reentrant locks, fair locks, unfair locks, optimistic locks, and pessimistic locks.
8. Which atomic classes have been used, and what are their principles.
9. Which concurrency tools have been studied under JUC, and talk about the principles.
10. 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, and the meaning of each parameter of the constructor, such as coreSize, maxsize, etc.
11. There are several ways to close the thread pool, and what is the difference between them.
12. If there is a third-party interface, there are many threads to call to get data, now it is stipulated that at most 10 threads can call it at the same time every second, how to do it.
13. Is the spring controller a singleton or multiple instances, and how to ensure the safety of concurrency?
14. Use three threads to print abc three letters sequentially, such as abcabcabc.
15. Have you ever used ThreadLocal, what is its purpose, its principle, and what should be paid attention to when using it.
16. If you were to implement a concurrency-safe linked list, what would you do?
17. What are the lock-free data structures, and what are the principles of their implementation.
18. Talk about wait and notify of java synchronization mechanism.
19. What is the CAS mechanism and how to solve the ABA problem.
20. Multithreading, what if the thread hangs.
21. The internal principles and usage of countdowlatch and cyclicbarrier, and the differences between them (such as countdownlatch's await method and how it is implemented).
22. How much do you know about AbstractQueuedSynchronizer, talk about the process of locking and unlocking, and what is the difference between exclusive lock and fair lock.
23. What is the difference between using synchronized to decorate static methods and non-static methods.
24. Briefly describe the use and difference of ConcurrentLinkedQueue and LinkedBlockingQueue.
25. What causes thread deadlock? How to release thread deadlock.
26. There are many threads (may be different machines), and they need to wait for coordination between each other to complete a certain kind of work. Ask how to design this coordination scheme.
27. Have you ever used a read-write lock? What is the principle and in what scenarios it is generally used.
28. Open multiple threads. If you ensure sequential execution, what are the ways to achieve it, or how to ensure that multiple threads are executed before you get the result.
29. The implementation of delay queue, the similarities and differences between delayQueue and time round algorithm.

 

6. TCP and HTTP
1. What is the difference between http1.0 and http1.1.
2. The TCP three-way handshake and four waved hands, why does the disconnection take 4 times, and if there are only two handshakes, what will happen?
3. The difference between TIME_WAIT and CLOSE_WAIT.
4. Tell me about several HTTP response codes you know, such as 200, 302, 404.
5. When you open a link with a browser, what steps does the computer do?
6. How does TCP/IP ensure reliability, and 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 the long connection of HTTP 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.


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


8. Algorithm
1. Find the smallest 10 out of 1 billion numbers.
2. There are 100 million numbers, of which 2 are repeated, find it quickly, time and space should be optimal.
3.2 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 the 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 reversal function.
8. Commonly used sorting algorithms, fast sorting, merging, and bubbling. The optimal time complexity of fast sorting, the worst complexity. The optimization scheme of bubble sorting.
9. The time complexity and advantages of binary search.
10. How to complete the reverse sorting of a built TreeSet.
11. What is B+ tree, B-tree, list the actual usage scenarios.
12. A singly linked list, delete the Nth data from the bottom.
13. 200 ordered arrays with 100 elements in each array, find the top20 element.
14. Singly linked list, find the element in the middle.


9. 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 it will lock the table or the row or something else.
11. Why use Btree to achieve, 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 to effectively use the composite index.
16. The difference between in and exists in mysql.
17. Possible problems with database auto-incrementing primary key.
18. The meaning of MVCC and how to achieve it.
19. Did you encounter sub-database and sub-table in the projects you have done? How do you do it? Is it useful for middleware, such as sharding jdbc, etc. Do you know their principles?
20. How to solve the master-slave delay of MYSQL.


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


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


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

Guess you like

Origin blog.csdn.net/weixin_45450428/article/details/104644172