In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the Java development interview questions". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it slowly to study and learn "what are the Java development interview questions" together!
Difference between TreeSet and HashSet.
As the name suggests, the first is the structural difference. The structure behind TreeSet is TreeMap, or red-black tree, which can be sorted automatically. It compares content through the equals method or compareTo method; behind HashSet is HashMap, key is out of order, only external sorting can be done. Since it is a Hash, then we need to rewrite the hashCode and equals methods of the object.
There is also a slight difference: HashSets can accept nulls, and there is only one; TreeSets cannot accept nulls by default, and throw null pointer exceptions directly.
How does HashMap resolve conflicts and expand mechanisms?
The internal structure of HashMap is actually array + linked list (after java8, if the length is greater than 8, it will be converted to red-black tree). HashMap is initialized with 16 hash slots by default. When storing an object, first, locate the hash slot through the hashCode of the object. If multiple objects fall into the same slot at the same time, a linked list is used to resolve conflicts in that slot. When a HashMap is created, it has a load factor. Each put operation checks whether the current capacity exceeds the threshold (initailCapacity*loadFactor). If it exceeds, it will be expanded to twice the current size. After expansion, the data needs to be hashed again, that is, the transfer method.
How does ConcurrentHashMap achieve high concurrency?
To put it simply, segmented locks (split locks) are used. Each lock is used to lock a portion of the data in the container, reducing contention between threads for locks.
4. How is thread pool usually used?
Ordinary scenes can be created using the factory class Executors. There are three common types: Single, Fixed and Cached. More often, the ThreadPoolExecutor class is customized directly for finer control.
Five, multiple threads wait to a certain node and then unified release there are several ways to achieve?
The classic is CountDownLatch, where the main thread blocks in the await method and each thread calls countDown. can solve some classic horse racing problems. Another variant is CyclicBarrier. Each thread blocks in the await method, reaching a certain threshold for collective release. You can also use some rudimentary APIs, such as the join method of Thread. Future's get method, etc., complex is not recommended.
VI. Database index structure.
B+ Tree, an index structure created to accommodate slow disks. It must be guaranteed to query by the leftmost prefix of the index. Hash is similar to HashMap, and the way to handle conflicts is linked list.
Select * from t where a=? and b>? order by c limit 0,100 How to add index?
When the order by field appears in the where condition, the index is utilized without a sort operation. Otherwise, order by does not appear sorted. Following the leftmost principle, I can create an index of (a,b).
What are clustered indexes and non-clustered indexes?
A table can have only one clustered index. The main index file and the data file are the same file. The default InnoDB supports clustered indexes. The data on the leaf node of B+ Tree is the data itself. MyISAM, on the other hand, does not support clustered indexes. Its leaf nodes store not the data itself, but the address where the data is stored. In terms of file structure, it will be divided into an index file and a data file.
9 Do you know CAP? What is CAP in redis?
Consistency, Availability, Partition tolerance. Generally, there is a trade-off between C and A. The redis simple master-slave model focuses on CP, i.e., requires higher consistency. redis-cluster, which is AP type, places more emphasis on availability.
10 How do you understand power? How is the idempotent of interfaces in a project done?
Idempotent refers to multiple executions with the same effect. For example, most Post operations, repeated order submission, etc., will only have one order generated successfully. There is also the case of messages, which are sometimes repeated due to the guarantee of most MQ at least once.
1. For Post requests, I generally force a jump to other pages after the request is successful to avoid refreshing the submission.
Complex operations are generally implemented using serial numbers.
3, some messages without serial number, when processing, it is necessary to carry out multiple checks and checks, and even introduce the message status table to ensure idempotent.
Eleven, explain the optimistic lock pessimistic lock.
Pessimism locks assume the worst, and every time you manipulate the data, you assume that someone else will modify it, so you lock it to ensure security. Visitors can only wait. Database row locks, table locks, java synchronization keywords, etc., are pessimistic locks. Optimistic locking, on the other hand, assumes the best case scenario. It doesn't lock the data, but it adds an extra decision operation. For example, a large number of CAS operations in the concurrent package, the mechanism to determine the old and new version numbers, etc.
The JVM determines whether the object is recycled.
The answer is GC roots. That is, starting from the root object, no object references it, then it is judged that this object is unreachable.
13 What is GCROOT?
1. Objects referenced in the virtual machine stack (local variable table in stack frame);
2. Objects referenced by JNI (i.e., native methods in general) in the local method stack;
3. Static variables and objects referenced by constants in the method area;
4. Reference object of active thread.
Can reflection get the name of a method in a class? What is the name of the parameter? What about parameter types?
Both are fine. After Java 8, parameter names are obtained through the Parameter class. But there is a premise, need to add compiler switch. Javac -parameters is off by default.
15. How to implement dynamic agents? What is the difference between CgLib and Jdk proxies?
Dynamic proxies are implemented in Java by implementing the InvocationHandler interface, and then initialized using Proxy. Cglib uses ASM's own generation framework, which can proxy ordinary classes, but not final classes, while jdk can only proxy interfaces.
16. What are the mainstream implementations of distributed locks? What is the difference between redis and zk locks?
Optimistic locking: Based on the version numbering mechanism and CAS implementation, independent of the storage in which the version number is stored.
Pessimism lock:
1. Based on database records, write data when entering and delete records when exiting;
2. Database row lock, such as distributed quartz, which is an exclusive lock;
3. Setnx function based on Redis (since most will set timeout, it is recommended to use set atomic function with px);
Based on Zookeeper.
Difference: redis acquisition lock is rotation training mechanism. After the lock is released, there will be multiple callers competing, and some tasks may starve. zk is a monitoring mechanism, and changes will be notified. In addition to unfair locks, fair locks can also be implemented.
17. What points should be considered in designing the second kill system?
1, data preheating seconds are instantaneous operation, do not wait for the flow to load data. Data can be preheated in advance, such as loading into cache.
2. Cache includes CDN cache and data cache. Ensure high availability of the cache system and subsequent landing of data.
3. Solve oversold introduction MQ, serialize operation inventory, no longer consume after reaching threshold, and close purchase function. Or directly manipulate the cache.
4. Traffic peak clipping By introducing MQ, the time-consuming business will be peak clipped and the user demand will be handled smoothly.
5, fuse current limit fuse, priority to ensure the main business. Limit flow, identify abnormal flow, block; at the same time, allow some requests to fail.
6. Elastic expansion When it is judged that the system load reaches the limit, it can resist the peak value by adding servers. It needs to open up the operation and maintenance environment and be able to expand rapidly.
Thank you for reading, the above is "Java development interview questions what" content, after the study of this article, I believe that we have a deeper understanding of Java development interview questions, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.