Summary of Java face questions

Source: Internet
Author: User
Tags iterable

1, the implementation of Spring AOP principle:
Spring provides two ways to generate proxy objects: JDK native Jdkproxy and cglib, which are used in a way that is aopproxyfactory based on the configuration of the Advisedsupport object. The default policy is to use Jdkproxy if the target class is an interface, or use Cglib to generate the proxy.
2, JDK native dynamic invocationhandle is the core of the JDK dynamic agent.
3. How the Cunrrenthashmap size is counted:
The total amount of data for each shard (default 16 shards) is counted first. If the count of the container changes during the statistical process, the size is obtained by means of a lock. The default retry is two times unlocked, two times the acquisition fails, then the lock is obtained. Monitor the change of count or not, there is a member variable Modcount contrast, each time the Shard on the Add or remove, the value will be increased or decreased correspondingly.
4, the Arrylist initialization size is 10 (that is, the call does not pass in the parameters of the construction method), so if you know in the use of capacity is best to initialize directly, so as to avoid the problem of expansion.
the expansion rules, the discovery of space is not enough, to expand.
expansion size rule: size after expansion = original size + Original size/2 + 1. (For example: The original size is 10, the size after expansion is ten + 5+1 = +), ArrayList is an array implementation, there is a size limit, theoretically the maximum is integer.max_value=2 of 31 square-1, the size is the norm implied limitations. The length of the Java array must be a nonnegative int, so its theoretical maximum value is Java.lang.Integer.MAX_VALUE = 2^31-1 = 2147483647.
5, LinkedList is a doubly linked list, no initialization size, there is no capacity to expand the mechanism, is always in front of the increase can, theoretically unlimited expansion.
6, HashMap initialization size is 16. The expansion factor defaults to 0.75, which can be directly formulated for initialization size and expansion because. When the current capacity exceeds the expansion factor, it will trigger the expansion, capacity expansion of one times. That is, if the default is 16, then the capacity to deposit 12,12/16=0.75 will trigger the expansion, expansion to the.
7, the four characteristics of business: ACID (atomicity, persistence, consistency, isolation). Isolation level of a transaction
dirty reads: One transaction modifies the data without committing, and the other transaction reads the data without committing the transaction.
non-REPEATABLE READ: A transaction that reads the data submitted by another transaction during the read process.
Phantom reads: The number of returns in a transaction multiple queries is different, that is, the number of first queries is 5, and the other transaction commits the data. The number of queries again and 5 (possibly less than 5 is also the concept of Phantom reading), there is a phantom read data.
both Phantom reads and non-repeatable reads are data that is queried for another transaction submission. The difference is that non-repeatable reads may be different for the same piece of data, and Phantom reads are for the number of data.

8, the isolation level of the transaction: READ UNCOMMITTED, read-committed, Repeatable read, serialization. The isolation level is raised sequentially.
UNCOMMITTED read: It is readable without committing other transactions, and is the weakest isolation level. Rarely used in real-world applications. This level can result in dirty reads, non-repeatable reads, and Phantom reads.
Commit read: The transaction is committed to be seen. This level is the isolation level for most of the default apps. is also the default isolation level for Oracle and SQL Server. This level prevents dirty reads. But it leads to non-repeatable reading and phantom reading.
Repeatable READ: Is the default isolation level for MySQL. Is whether the data is inserted or the data is deleted and the transaction is committed. The data that is read in the current transaction is always the same. This leads to a problem where other transactions modify the amount of data. But my current transaction query is still the old inaccurate amount of data. This is the disadvantage of this thing. can cause Phantom reads.
Serialization: Is the highest isolation level. He actually locks the data on each line. Ensure the accuracy of data reading. But the reason for the lock is the least efficient. Not really applied.
9. Volatile does not guarantee the atomicity of the operation but ensures the visibility of the memory. That is, the data that is accessed between different threads is up-to-date. To ensure atomicity, you must use the Atomic class. This ensures that the read-write is atomic at the hardware level, unlike the normal int type, which is executed in two steps (reading the variable value first and then at + +)
10, write wait method write in If or loop call AH: should use loop, because the current condition is not satisfied when will wait, so with the loop.
11, multi-threaded pseudo-sharing: In fact, multi-threading is more CPU or multi-core CPU has its own cache. The write operation is the process of writing to main memory through the CPU. Main memory is the real share. The CPU cache between so multithreading is pseudo-shared.
12. Thread Local variables: shared by threadlocal, but sharing has a problem that does not release the memory leaks need attention.
13. The difference between Java sleep and wait: Sleep is short-lived and does not release the lock, and wait releases the lock for other threads to use.
14, what should Java use to represent the price. Look at the accuracy of the requirements, precision with bigdecimal, generally with double can.
15, A = a + B with a + = B difference a+=b security will not error The result is the type of a. A=A+B conversion to int adds an error.
16, 3*0.1 = = 0.3 The result is false because Java is a floating-point number can not be accurately identified.
17, int and integer use the process, the integer will be more resource-intensive
18, Java string is immutable one reason is that the designers think the use of a large frequency, design is immutable easy to share and security.
19, Java Swich can use string, jdk1.7 later can, in fact, inside the bottom is bar string to hashcode implementation.
20. Explain Java heap space and GC? When the Java command starts the Java process, it allocates memory, allocates space in the heap memory when the object is created, and GC primarily reclaims garbage collectors with no reference space in the heap memory.
21. Can you guarantee GC execution? No, hard-coded system.gc () can be executed, but not guaranteed. Look at it in the mood.
22, Java heap and stack differences. The heap is put on shared objects that can be recycled by GC. The stack is the place of the method and local variables, is thread-specific, is freed when exhausted, the heap needs to be recycled by GC itself.
23. java Static final transient keyword difference:
static: Modifies variables, methods, blocks of code, static modifiers that belong to the class that are not part of the instance.
Final: Chinese is immutable and can be decorated with classes, methods, and variables. The class is not inheritable when the class is decorated, and the class is immutable when the modification method does not allow rewriting or modifying variables.
transient: This keyword is used in Java serialization and is ignored when the variable Java that is modified by that keyword is serialized.
normally: Static and fianl are used as a piece of static because there is only one copy of it. Final is immutable. This ensures that immutable data is retained only for one copy.
25, enhanced for loop foreach is a syntactic sugar, the collection class wants to use must implement the Iterable interface, because he is the bottom of the iterable iterator traversal. The array does not implement an iterator interface, and the underlying loop iterates through the data reference implementation. That is, the enhanced for loop is implemented by invoking the underlying.
26, Hashtable and HashMap difference, Hashtable is the old API left, all his methods are synchronized, so is thread-safe, but inefficient. The implementation of Hashtable and HashMap is the same, all through the hash table, and then there are entry static class (can be understood as a one-way linked list and save the key and value) to expand. jdk1.8 HashMap is implemented with array + linked list + red black tree (jdk1.8 added), the chain table length is greater than 8 when automatically converted to red black tree, treemap based on the red and black binary tree implementation. Guarantee the order.
27, the hashset of the bottom realization principle is hashmap. Only the HashMap key is used.
28, Copyonwrite is to write the time to lock a copy of the data to the new data to write operations, after writing the reference point to the new modified data. For concurrent scenarios where there is less read-write. The disadvantage is that memory is large, can not guarantee real-time consistency, can only guarantee the final consistency.

Summary of Java face questions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.