This is the most useful java interview question I have ever seen, and I have interviewed countless companies to sum up.

One, the basic part of Java


1. Three characteristics of Java object-oriented


2. What are the basic data types in Java and their occupied bytes

3. The difference between int and Integer

4. The difference and usage scenarios of String, StringBuilder, StringBuffer

5. The difference and usage scenarios of ArrayList, Vector and LinkedList

6. The difference between Collection and Collections

7. The difference between List and Map

8. The difference between HashMap and HashTable

9. HashMap underlying implementation principle and expansion mechanism


10. What kind of HashMap is suitable as a key

11. The difference between final, finally, and finalize

12. The difference between sleep() and wait()

13. The difference between abstract classes and interfaces, and usage scenarios

14. The difference between Overload and Override

15. The difference between forward and redirect

16. The working mechanism of the connection pool

17. What is serialization

Second, the third-party framework part


1. What is AOP and what is the underlying principle of Spring AOP.
AOP is aspect-oriented programming, used to add some additional functions without changing the original logic, such as transaction management, logging, caching, and permission control.
Spring AOP is based on proxy.
If the target object implements the interface, JDK dynamic proxy is used by default.
If the target object does not implement the interface, CgLib is used for dynamic proxy.
If the target object implements the interface and the CgLib proxy is forced, then the CgLib dynamic proxy is used.

2. What is IOC and IOC injection methods? Which
IOCs are translated as inversion of control, and they are also called DI (dependency injection).
IOC is the IOC container responsible for the life cycle of the object and the relationship between the objects.
Inversion of control is what you should do and let the system do it. For example, you usually need to pass new to get an object, while using IOC is to inject the object into the injected object after IOC is created.
Annotation injection (Spring), constructor injection, setter method injection, interface injection (not recommended)

3. The difference between #{} and ${} in Mybatis
#{} is pre-compiled to prevent SQL injection. ${} is directly spliced ​​in the SQL statement.

4. What is the core annotation of Spring Boot and which annotations it is composed of?
Core annotations: @SpringBootApplication
contains:
@SpringBootConfiguration realizes the configuration file function
@EnableAutoConfiguration opens the automatic configuration function
@CompoentScan component scanning function

5. How does SpringBoot read configuration files
using @Value annotations
on properties. Use @ConfigurationProperties annotations
on classes. Reading specified file annotations can be
obtained by injecting Environment objects on the class using @PropertySource (yml file reading is not supported) .

6. The difference between SpringCloud and Dubbo
SpringCloud uses HTTP-based REST API, and Dubbo uses RPC.

7. SpringCloud's Hystrix circuit breaker feature
request fusing: the request service failure exceeds a certain percentage (default 50%). The circuit breaker will switch to the open circuit state. At this time, all requests will not be sent to the back-end service, and the circuit breaker will remain open for a period of time. After time (default 5 seconds), it will automatically switch to the semi-open state. At this time, if the next request is successful, the circuit breaker switches back to the closed circuit state, otherwise it switches to the open circuit state again.
Service degradation: For query operations, a fallback method can be implemented. When an exception occurs in the request service, you can use the value returned by the fallback method.
Dependency isolation: resource isolation is achieved through thread pools. For example, one service calls two other services. If these two services are in the same thread pool, then if one service is stuck, the following request will come again, which will lead to the following request Will be stuck waiting.
Request cache: cache the result of the last request and return it to subsequent requests.
Request merge: merge multiple requests into one request to improve efficiency.

Three, MySQL database part


1. Four characteristics and isolation levels of things


2. MySQL optimization related


3. The difference between MySQL storage engine InnoDB and MyISAM


4. Under what circumstances does MySQL use indexes?

5. MySQL sub-database sub-table strategy


Four, extended reading


1. Regarding Spring's choice of JDK and CgLib dynamic proxy, the
following code can be obtained by consulting the org.springframework.aop.framework.DefaultAopProxyFactory class in the Spring-AOP package:

As you can see, Spring first uses the isOptimize() method, isProxyTargetClass() method, and hasNoUserSuppliedProxyInterfaces() method to judge. The meanings of these three methods are as follows:

After understanding the meaning of these three methods, the next reading of the code is very simple.
If the return value of any of the above three methods is true, proceed to the next step of judgment. If all return values ​​are false, it means that CgLib is not mandatory, or the interface is implemented, and JDK dynamic proxy is used.
In the second step of judgment, the targetClass is first judged to be empty, and then it is judged whether it is an interface or proxy class, and if it is, the JDK dynamic proxy is used.
Otherwise, use CgLib for proxy.


2. Why CgLib can proxy any class, but still needs the dynamic proxy of JDK? The difference between CgLib and JDK dynamic proxy.
This has to talk about the characteristics of CgLib: slow creation speed but fast execution speed, while the dynamic proxy of JDK is just the opposite: fast creation speed but slow execution speed.
If you continue to use CgLib to create proxies when the program is running, the performance of the system will be greatly reduced. Therefore, it is recommended to use CgLib to create proxies during system initialization and put them in the Spring ApplicationContext.

Thanks for reading, and support. I wish you all the offers you like in fights! Click here to receive benefits