SQL > select, FROM, where, group by, order by, having; Select * from (select * from (select * from) WHERE (select * from (select * from) WHERE (select * from) WHERE (select * from) WHERE (select * from) where (select * from) where (select * from) where (select * from) where (select * from) where (select * from) where (select * from) where (select * from) where (select * from) where (select * from) where (select * from) from–where–group by–having–select–order by

2. What is the difference between resultMap and resultType in MyBatis? A: resultMap is more powerful, and you can customize the field alias (Column: library table field name, property: entity class property name). ResultMap is used in one-to-many scenarios. The resultType is a one-to-one mapping between the entity class and the database table field, and directly returns the type. Both cannot exist at the same time

3. What are the differences between hashMap and hashTable? 1. Key-value storage: the value of a single linked list increases when the value exceeds the threshold. 2. The thread is not safe and applies to single threads (multiple threads may cause deadlocks). It is recommended to use concurrent and send concurrentHashMap (a piecewise lock) to concurrentHashMap. 3. There can be one NULL key and multiple NULL values. (Use containsKey() to check whether a key exists.) 4. High efficiency hashTable: 1. Key-value storage. 2. Thread safe for multiple threads because each hashTable method adds Synchronize; 3. The key and value cannot be null. 4. The efficiency is low

4.Bean life cycle? Answer: 1. Instantiate the bean object (via constructor or factory method) 2. Set object properties (setter, dependency injection, etc.) 3. If the Bean implements the BeanNameWare interface, the factory calls the Bean’s setBeanName() method to pass the Bean’s ID. 4. If the Bean implements the BeanFactoryAware interface, the factory calls the BeanFactoryAware() method into the project itself 5. Pass the Bean instance to the Bean’s front processor postProcessBeforeInitialization (Object beans, String beanName) method 6. Call the Bean’s initialization method 7. Pass the Bean instance to the Bean’s rear processor postProcessAfterInitialization (Object beans, String beanName) method for 8. 9. Before the container closes, call the Bean destruction method; (Simple description: Instantiate — Set properties — Check ware interface — Initialize — Use — Destroy)

5. Four characteristics of transactions? Dirty read, phantom read, unrepeatable read? 1. Atomicity: All succeed or all fail 2. Isolation: Multiple concurrent transactions do not affect each other 3. Consistency: Data integrity remains consistent before and after transactions 4. When the transaction completes, the database changes are permanent 5. Dirty read: uncommitted data is read. 6. Phantom read: Data is read repeatedly and the total amount of data is inconsistent. 7. Non-repeatable read: Data is read repeatedly and inconsistent

6. How to solve cross-domain problems? Cross-domain problems are bound to occur when the current page and the background run on different servers. The same origin policy means that the domain name, protocol, and port are the same; Different sources produce cross-domain. Answer: 1. Jsonp with Ajax, which only applies to GET request 2. “//origins: a list of domains allowed to access, “*” for all; MaxAge: Maximum cache duration (in seconds) before a response is prepared.

7.IOC and AOP can say something? A: INVERSION of control: The IOC gives the right to create objects to the core container (which is responsible for the life cycle and relationships between objects). There are two main ways to implement IOC: dependency injection and inversion of control (DI: the IOC container dynamically injects the external resources needed by the current object to us; Four types of injection: annotation injection, set injection, constructor injection, static factory injection) —- When a role needs assistance from another role, in traditional programming, it is usually the caller who creates the instance of the called. But the job of creating the called in Spring is no longer done by the caller, so it’s called inversion of control. Spring does the job of creating the called, and then injecting the caller, which is also called dependency injection. AOP is faceted programming: it complements and complements OOP, which introduces concepts such as encapsulation, inheritance, and polymorphism to establish an object hierarchy. AOP technology, mainly divided into two categories: one is the use of dynamic proxy technology, the other is the use of static weaving. – for example, something I like you to write a method used to do some things, but this requires login user can do, you’ll be able to verify, before this method performs record after operation on the log, the front and back of these has nothing to do with the business logic code is extracted in a class, this class is to cut (Aspect), This method is called a Pointcut, and what you do before and after is collectively called Advice.

A: Filters: In layman’s terms filters filter out what you want (i.e., when a bunch of requests come in, filter out the illegal ones), such as the part of the request that you want, depending on the servlet container. (Application scenario: URL-level permission control; Filter sensitive terms (prevent SQL injection); Springboot custom filter implementation steps: 1. Create a Filter class using @webFilter; Interceptor: Interceptor that intercepts the requested interface before it is accessed and then adds some action before or after it. Interception is an implementation strategy of AOP (underlying is dynamic proxy-reflection). Interceptors are primarily used to reject requests according to specified rules. For example, terminate some processes. (Application scenario: Token authentication; Request data verification; User authority verification; Release specified interface; Blocking logged-in users). Springboot custom interceptor implementation only need two steps: 1. Custom interceptor, implement HandlerInterceptor interface; 2. Register interceptors. Interceptors are more powerful in terms of flexibility. They can do everything a Filter can do.

9. Composition and underlying implementation of HashMap? A: There are two basic data structures in Java, arrays and linked list arrays: quick queries, difficult to add and delete by index; Linked list: slow query, need to traverse the entire list, easy to add and delete; A HashMap consists of an array and A linked list, and is A binary tree (jdk1.8). When the list reaches A certain length, the list becomes A red black tree (A has two nodes BC and B and C have DEF nodes BC and C). Fast storage: Very fast when we get and put a HashMap;

2. Quick search: When we get a value through key, the time complexity is very low and the efficiency is very high;

3. Scalability: 1 Array expansion, side length. 2. A single-line list becomes a red-black tree if it is longer than 8.

10. Do you know the microservice architecture? A: (Talk about the five components of springCloud and name all you know) Eureka: Service registry Zuul/Gateway: service Gateway (similar to Nginx reverse proxy function; The Gateway is based on Spring Boot2.0, replacing Zuul) Hystrix: circuit breaker

12. How many ways can microservice dynamic configuration be implemented? A: 1. Use Consul as a registry (microservice configuration can be managed online and dynamically loaded). 2. Apollo of Ctrip (recommended, configuration changes take effect in real time (hot release)); 3. Config of springCloud family bucket (I heard that it is not very easy to use and has not been used in the project yet); 4. Ali’s Nacos (can do service registry, also can do configuration center, easy to listen to friends say)

Mysql optimizes mysql in several ways. A: mysql optimization is mainly divided into the following four aspects: 1. Design: storage engine, field type, normal form and inverse normal form, reduce The Times of accessing the database

2. Functions: index, cache, partition sub-table.

3. Architecture: master/slave replication, read/write separation, load balancing.

4. Reasonable SQL: reasonable use of JOIN, try not to use SELECT *, in, not in,or.

A: SpringBoot is basically an extension of the Spring framework that eliminates some of the complexities of Spring configuration

14. Has Redis used it? String: a key corresponds to a value. Hash: Map

ZSet: an unordered collection of String type. ZSet: an unreplaceable, ordered collection is used in one scenario: mobile phone number verification code login function, session sharing.
,object>

15. What middleware have you used? A: RabbitMQ (message queue)

MyCat (separate table, separate read and write)

Mybatis (Persistence Layer Framework)

Swagger2 (Swagger – UI, Rest APIs Document Generation Tool)

PageHelper (Physical paging plug-in)

16. What are NIO, BIO and AIO in Java? A: BIO: Synchronous blocking IO, simple to understand: one connection one thread, BIO is suitable for a relatively small number of connections and fixed architecture, this method requires high server resources, concurrency is limited to the application, jdK1.4 before the only choice, simple single-program intuitive. NIO: synchronous non-blocking IO, simple to understand: one thread per request, NIO is suitable for a large number of connections and relatively short (clean operation) architecture, such as chat server, concurrency is limited to the application, the programming is more complex, jdk1.4 started support. AIO: asynchronous non-blocking IO, simple to understand: a valid request for a thread, AIO is suitable for the number of connections, and the connection is relatively long (heavy operation) architecture, such as photo server, fully call OS to participate in concurrent operation, programming is more complex, jdk1.7 began to support.

A: Factory pattern: The BeanFactory pattern is an embodiment of the simple factory pattern, which is used to create instances of objects. Singleton: Beans default to singleton; Proxy mode: Spring’S AOP uses JDK dynamic proxy and CGLIB bytecode generation techniques; Template methods: Used to solve problems with duplicate code, such as RedisTemplate, JpaTemplate. Observer mode: Defines a one-to-many dependency between object keys. When an object’s state changes, all dependent objects are notified to be updated, as in Spring’s implementation of listener – ApplicationListener.

18. What front-end frameworks have you used? Answer: the bootstrap; EasyUI; LayUI Thymeleaf (SpringBoot does not support JSP by default, Thymeleaf template engine is used by default)

19. What does ThreadLocal do? A: waitingThreadLocal is the local variable that creates the thread. All threads of an object share all of its local variables, so these variables are not thread-safe and we can use synchronization techniques. However, when we don’t want to use synchronization, we can choose the ThreadLocal variable. Each Thread has its own Thread variable, and they can use get(),set() to get their default values or change their values internally. (To put it bluntly, ThreadLocal wants to keep member variables safe in multiple threads.)

Do you understand multithreading? A: You can answer this question in the following aspects:

  • There are four ways to create multithreading:

1. Inherit Thread class (disadvantages: Java only supports single inheritance) 2. Implement Runnable interface (can return execution results, run() method can not throw exceptions, only internal digest) 3. Implement the Callable interface (does not return execution results, the call() method allows exceptions to be thrown) 4. Create a thread pool by using the Executors tool class. You can specify or disable the thread pool.

  • What causes thread insecurity?

A: If we create multiple threads that share data, we may have a thread-safe problem: when one thread is working on the shared data, the other thread will join in, causing problems with the shared data.

  • Thread unsafe solution?

When one thread is required to operate on shared data, other threads will not have the opportunity to perform shared data until it has completed the operation. Java provides two ways to implement synchronized mutually exclusive access: synchronized and Lock.

  • What is the difference between wait() and sleep() in multithreading?

Wait () releases the currently held lock and waits, while sleep() does not release the lock; Wait () can only be used within synchronized blocks or synchronized methods, and sleep() can be used anywhere; Wait () notify() wakes up only one thread notifyAll() wakes up all threads without catching exceptions, and sleep() does; Recommended: Because sleep() does not release lock resources, it can cause deadlock problems, while wait() does not, and it is generally recommended to use wait().

ThreadPoolExecutor() ¶ A thread pool is basically a workerSet of threads and a workQueue of blocking threads. When a user submits a task to a thread pool, the thread pool first places the task in the workQueue. The threads in the workerSet are constantly fetching threads from the workQueue and executing them. When there is no work in the workQueue, the worker blocks until there is a task in the queue and then fetches it to continue executing.

Mysql > select * from ‘mysql’; A: Yes, the primary key unique index is used most often.

  • What is an index? An index looks up a table of contents just like a dictionary.
  • What index types do you know? Unique: cannot have the same value, and null values are allowed. Index: allows the same index content to appear. Promary key: do not allow the same value; Fulltext text: can target a word in a value, which is inefficient. Combination: To group multiple fields into an index. The combination of column values must be unique.
  • Indexes can improve query efficiency, but reduce table update efficiency. Creating indexes takes up disk space. Creating too many indexes causes index files to swell.

A: The way a proxy class creates proxies while a program is running is called dynamic proxies. The most straightforward example is Spring’s aspect oriented programming AOP, where we can perform some operations before and some operations after a pointcut, which is a method. The class in which these methods reside must be proxied, and some other action must be taken during the proxiation process.

24. How are transactions handled in the project? A: Spring provides a number of transaction management mechanisms, mainly programmatic and declarative. Programmatic transaction: refers to the manual management of transaction submission, rollback and other operations in the code, code intrusion is very strong, such as the following example:

  try{ transactionManager.commit(status); }catch (Exception e) { transactionManager.rollback(status); throw new InvoiceApplyException("Abnormal failure"); }Copy the code

Declarative transaction: Based on AOP aspect, it decouple the concrete business and transaction processing part, the code is very low intrusion, so declarative transaction is used more in the actual project development. (Declarative transaction implementations are also divided into TX and AOP-based XML configuration files and @transactionL annotations.) Example:

Transactional works on interfaces, classes, and class methods.
@Transactional(rollbackFor = Exception.class)
Copy the code

The interviewer then asks: the way annotations are used in the project does not roll over. Can you explain why? 1. Check if your method is public; Is your exception type unchecked (Error or RuntimeException (e.g., null Pointers, 1/0) : unchecked: Unchecked is what is called an unchecked exception. Checked exceptions: Our compiler detects them and calls them checked exceptions. 3. The database engine should support transactions, if MySQL, note that the table should use a transaction engine, such as InnoDB, if myISam, transactions will not work; 4. Whether parsing annotations is enabled;

<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
Copy the code

5. Has Spring scanned your package? The package under org.test is scanned as follows

<context:component-scan base-package="org.test" ></context:component-scan>
Copy the code

6. Check whether a method is called in the same class (for example, method A calls method B in the same class) 7. Is the anomaly caught by you.

A: In the past, when we call a method in a class, we always ask for new objects. Now with IOC, we hand the object to the BeanFactory (bean factory) for management. When we use it, we directly fetch it from the factory. Ioc is achieved through factory mode, reflection mechanism!

A: The entire Jvm can be divided into two large regions. Threads share region 1. Method area: used to store information about classes that have been loaded by the virtual machine, constants, static variables, code compiled by the just-in-time compiler, etc. 2. Heap: The largest area of memory managed by the Java virtual machine, which is shared by all threads. The Java heap is the main area managed by the garbage collector (GC heap from the point of view of memory collection, the collector basically uses a generational collection algorithm, so the Java heap can also be subdivided into: Thread private area (live with thread, die with thread) 1. Virtual machine stack: Memory model of Java method execution, storage of local variable table, operation stack, dynamic link, method exit, etc. 2. Local method stack: when a local method is executed, a stack frame will be created, which is used to store the local variable table, operand stack, dynamic link and exit information of the local method; 3. Program counter: A program counter is a small memory space that can be viewed as a line number indicator of the bytecode being executed by the current thread.

27. What about garbage collection for JVM? A: The purpose of the garbage collector is to collect (clean up) and find useless objects. To allow the JVM to use memory more efficiently.

What needs to be recycled? The memory of program calculator, stack and local method stack is generated and destroyed with the thread. Memory allocation is generally confirmed at compile time; In this way, the allocation and reclamation of memory in these regions are deterministic; So there is no need for the JVM to manage the collection; When a method terminates or a thread terminates, memory is naturally reclaimed. The heap and method area are allocated dynamically, and only during the running of the program is it known which objects to build. Memory allocation and reclamation are dynamic. So the JVM only needs to focus on this part of memory!!

When is it recycled? In fact, very simple —– is no one to use things, you can recycle! In the JVM, assuming that the object has no threads or methods to use proves that the object is recyclable. How do you tell if an object is not referenced or used? The first algorithm – reference counter algorithm (add a reference counter to the object, when there is a reference to it, the counter is +1, when the reference is invalid -1, when the counter is 0, it can not be referenced; This method is simple and efficient but has the disadvantage of referring two objects to each other; There is no way for gc to reclaim this object; Therefore, this algorithm is rarely used. The second method – reachability analysis algorithm (the algorithm idea is through the GC_root node as the starting point, search down, search through the path is called the reference chain; When an object is not connected to a GC root, then the object is no longer used and can be reclaimed.

In what way? A: 1. Mark-clear algorithm (mark well first, and then uniformly recycle; Fragmented memory generated after clearing;) 2. Replication algorithm (divide the available memory into two pieces of equal size, use one piece at a time, and copy the surviving objects to another piece when the memory is used up; Then empty the used memory once;) 3. Generational collection algorithm (according to the life cycle of objects, it can be divided into Cenozoic and old age; Different algorithms are used for different generations;)

28. How does the JVM GC, Generation, generation, persistent, and what does it store? A: the JVM GC algorithm are: reference counter algorithm, root search method (details refer to 27) generation: the object of the new generation Old s: in the young generation still alive after N times garbage collection of objects, it will be in the old generation (life cycle longer object) in the last generation: used to store static files, now Java classes, methods, etc

A: A StackOverflowError is raised if the thread requests a stack depth greater than the virtual machine allows. OutOfMemoryError is thrown if the virtual machine cannot allocate sufficient memory space while dynamically expanding the stack. Ask the experienced students, said the memory usage skyrocketed, generally is the memory leak caused by middleware. Since our online services are developed in the Java language, we can start with the JVM garbage collector (GC) to get a visual view of the JVM memory status. (jstat -gcutil pgrep -u mapp Java 1s)

30. What is your understanding of Java reflection? A: There are four ways to create objects in Java. 1. Use the new keyword: this is the most common and easiest way to create objects. Using the Clone method: Whenever we call the Clone method on an object, the JVM creates a new object with the contents of the previous object copied in 3. Use deserialization: When we serialize and deserialize an object, the JVM creates a separate object for us 4. Reflection What is reflection? Reflection is mapping parts of a Java class into Java objects that you can take and do something with. (Various parts: member variables, methods, constructors, etc.) How to get reflected classes? First of all, the code we write is stored in a.java file, but it will be compiled, and the compiled.class file will actually execute. Java is an object-oriented language, everything is an object, so Java thinks that these compiled class files, this kind of thing is an object, and it’s abstracted into a class, and that class is called class.

Mysql transaction isolation level? A: 1. Uncommitted read: All transactions can see the data of uncommitted transactions; 2. Commit read: the transaction can be queried only after it is successfully submitted. 3. Repeat read: When multiple instances of the same transaction read data, uncommitted records may be queried and phantom reads (default mysql level) may occur. 4. Serializable: Sort the data forcibly and add a shared lock on each read row. It causes a lot of timeouts and lock contention.

32. How to handle RabbitMQ dead letter queues? A: Do not want: (if no processing is done, when the message consumption exception, the default will be repeated retry, which is obviously not desirable) we want: can specify the number of retries, retry after the queue, and then the queue can be manually processed 1. Exchange and RoutingKey 2 need to associate a Queue with a dead-letter Queue. On the UI page, you can see that the message enters the dead-letter Queue after multiple retries. 3. Process the dead-letter Queue –3.1 Manually Process the dead-letter Queue –3.2 Route the messages in the dead-letter Queue to Queue for processing after the system is normal

A. Synchronized B. Synchronized C. Synchronized D. Synchronized Synchronized is a common approach to concurrency in Java, and one of the simplest. (We all know that Synchronized synchronizes threads, meaning that only one thread executes code at a time.) Three main functions: (1) ensure that threads are mutually exclusive access synchronization code (2) ensure that changes to shared variables are visible in a timely manner (3) effectively solve the reordering problem.

34. How many ways can Mybatis load Mappers? Resource 2.url 3.class 4.package (priority highest)

35. The underlying principle of Mybatis? How does Mybatis acquire data source? A: The creation of mybatis data sources uses factory mode. There are two basic types: data sources with connection pool and data sources without connection pool (similar to JDBC). How to obtain SQL from mybatis? How does Mybatis operate? Four. How many actuators does Mybatis have? Mybatis level 1 cache default state? How do you create it? How do you use it? This will continue to be updated


I wish everyone seize the opportunity in 2021, salary technology are better