“This article has participated in the good article call order activity, click to see: back end, big front end double track submission, 20,000 yuan prize pool for you to challenge!”
The following interview questions are based on the author’s experience. They are not plagiarized. They are only personal opinions
This article does not apply to those who fight for BAT and favor algorithms and data structures in first-tier cities. It only supports the majority of digital farmers in second-tier and third-tier cities, who focus on interface writing and function implementation and struggle in ordinary positions, including myself. The following answers are personal understanding and a simple summary, if you want to understand in detail, please baidu.
First introduce the following big Shenyang Java salary level, according to the overtime situation or business trip up and down slightly
Intern: 3K-4K Primary development: 4K-6K Intermediate development: 6K-8K Advanced development: 9K-12K Architect: 12K-15K Real big guy (dafang experience, high concurrency experience, Dafang management experience) : 20K or soCopy the code
Java based
- Break,return,continue(>4)
Return: directly return break: used in the loop, break out of the loop, no further loop execution. Continue: Used in a loop to break out of the loop, terminate the loop, and continue with subsequent loops.Copy the code
- Static, final keyword (>4)
The main purpose of a final is to prevent a modified object from changing. 1. Modify variables: Variables are not allowed to change. 2. Modifier: prevents inherited overwrites from changing the method. 3. Decorated class: This class is not allowed to inherit. Prevent being overwritten. Static: can be used when no object is created. 1. Modified variables: are global variables that are placed in the method area after class loading. They are loaded only once during initialization and are shared globally. If you do not assign an initial value, it defaults to 0. 2. Modify methods: Static methods cannot call non-static variables and methods (because non-static methods and variables require an object to call, but are not possible to use). Method, but not an object. Since this is also called from an object, it is not possible to use this. Static methods can be called from the class itself without creating any objects. This is actually the main purpose of static methods. The advantage of static methods is that they can be called directly without generating an instance of the class. A member decorated by a static method no longer belongs to an object, but to its class. It can be accessed only by its class name, without consuming resources to repeatedly create an object. Static is already in memory when the class is first loaded and is not freed until the program ends. Member functions that are not static are reclaimed by the JVM immediately after they are used. When to use static? If the method is to be used as a tool, it is declared static and can be used without a new object. For example, connect DB can declare a static method of Connection(), 3. Decorated classes: There is only one case, static inner classes. 1. The inner class can only access the static variables and methods of the outer class. 2. Static inner classes can name ordinary variables and methods. Ordinary inner classes cannot name static methods and variables. Usage scenario: Static inner class usage scenario is when the inner class needs to use the inner class, but the inner class does not need the resources of the outer class, and the inner class can be created alone. 4. Decorated code block: Can optimize performance, called when class loading. It is called only once. (load sequence: static block of parent class - static block of subclass - constructor of parent class - constructor of subclass). Only variables defined before the static block can be accessed. Variables defined after it can be assigned, but cannot be accessedCopy the code
- Introducing inner classes (>4)
Inner classes include: member inner class, local inner class, static inner class, anonymous inner class. Multiple inheritance can be implemented. Different inner classes can inherit from different classes. 2. Inner classes are better hidden. 3. We can use anonymous inner classes when we don't want to write the implementation of the interface or when we just want to use the object once. 4. Each inner class is a separate individual.Copy the code
- Equals (>4) equals(>4)
== : Compares the address, that is, the stack. Ps or some constants in the method area. Equals: compare the value, i.e. the heap. It's usually an encapsulation type.Copy the code
- Talk about int and integer(>4)
Int: the basic type, placed in the method area, can be compared using ==. Integer: indicates the encapsulation type. Use equals to compare objects. When objects are passed values (not evaluated), it is generally recommended to use an INTEGER because an INTEGER can have different meanings than nullCopy the code
- (>5)
Commons package, FastJSON package, etcCopy the code
- Describe the difference between the list map hash class (>5)
Collection Collect is the top-level interface for the collection class that stores data. So you can't instantiate, you can only implement collection, which is of variable length, and collections are reference types. List and set are the implementation classes of collection. List is ordered, can be repeated, can be empty, and you have ArrayList, LinkedList, and Vector. Linklist storage in the way of linked list, add and delete faster, thread is not safe, high efficiency. Arraylist is stored as an array, which makes query faster, more efficient, and less thread safe. Vector thread safety, low efficiency and growth rate of 100%, large amount of data in the data set can not be repeated, disorderly, treeset, hashset, linkhashset implementation class for the set. Hashset data structure is a hash table, sorted by hash value, there is no duplicate value, judged by hashCode and equals. Thread safe, fast access. The hash value of the element is obtained from the element's hashcode method. The HashSet first determines the hash value of the two elements. If the hash value is the same, the HashSet then compares the equals method. If equals is false it's not the same element. = false = false = false = false = false It's just a hash of a column. Treeset can be naturally ordered. Not repeatable. LinkedHashSet will save inserted sequence map map is the map interface implementation class, for key/value pairs, including a hashmap, treemap, hashtable, linkedtreetable hashmap and the only key, the key value can be null, the thread are not synchronized. TreeMap can sort the keys in a collection. LinkedHashMap holds the insertion order of records. Hashtable Neither key nor value is allowed to be null; It supports synchronization of threads, meaning that only one thread can write to the Hashtable at any one time, thus making hashTales slower to write. Thread safety linkList ArrayList HashSet LinkHashSet thread unsafe Vector HashTable for thread safe stringBuild for thread unsafe StringBuffer for thread safe LinkedXxx: LinkedXxx: LinkedXxx: LinkedXxx: LinkedXxx: LinkedXxx: HashXxx: hashtable. Dependencies on two methods: hashCode() and equals() TreeXxx: The underlying data structure is a binary tree. Sorting in two ways: natural sorting and comparator sortingCopy the code
In small companies, these answers are already very good,
- Integer What comparison value to use (>7)
Use equals (), but you can also use the == comparison between -128-127 (int) and -128-127 (int).Copy the code
- Introducing BigDecimal (>7)
In the amount of numerical calculation used to avoid accuracy lossCopy the code
- The Java Memory Model (>8)
The JVM is the Java Virtual Machine, and each JVM includes the heap, stack, local method stack, method area, instruction counter, and other hidden registers. Heap: Responsible for storing object instances. Stack: Stores references to basic types and objects. Method area: store class static variables, steady on, class information, etc. Local method stack: This is similar to a stack, except that it holds methods.Copy the code
More on this net, space is limited, ask oneself baidu.
- Tell me about the gc (> 8)
If you run out of memory space, the JVM provides GC- or garbage collection. Automatic garbage handling when memory is out. Garbage is usually recycled from piles. The heap is divided into three parts: the Cenozoic generation, the aging generation and the persistent zone. The Cenozoic generation is divided into Eden, Survivor1 and Survivor2. When an object is created, it will be put into Eden, and the larger one will be directly put into the aging generation). When Eden's memory is full, minor GC will occur. In this case, Eden will clear the unused space in memory and put the remaining data into Survivor1. When Eden's memory is full next time, repeat the previous operation, and data in Eden and Survivor1 will be stored in Survivor2 together. Until a Survivor1 or Survivor2 is fully stored, then the data of a fully stored Survivor1 or Survivor2 will be stored in the old generation. When the old generation is fully stored, full GC will occur and the memory of the old generation will be cleared.Copy the code
More on this net, space is limited, ask oneself baidu.
- (>8) How can a private class or method be reflected? (>8)
Private types can be reflected toCopy the code
- Explain your understanding by understanding memory patterns and GC (>9)
Collection classes should be used with care to prevent memory leaks because GC brings the system to a temporary stop. Reduce the number of new times, because of the limited space to occupy heap memory, please baiduCopy the code
- A =b returns a value of 128. A =b returns a value (>10)
127 Returns true. 128 returns falseCopy the code
Java foundation is definitely an essential question, for early and intermediate development, ask more, this is a skill that will accompany your career, and not too difficult knowledge points, need a lot of preparation.
The database
- Simple SQL writing such as associating two tables (> 4K)
Not much saidCopy the code
- Left connection and Right connection (> 5K)
Left join on Left join on right join on Right join on left join on right join onCopy the code
- Why indexes speed up queries (> 7K)
Because index full table search is not applicable, this will result in multiple disk reads, which is a physical behavior, so it is slow. (IO) Use index 3 IO to achieve query, so it will increase the speed.Copy the code
Here only provides a simple summary, specific baidu
- What happens when the index will not go (>7k)
2.<>, IN,NOT IN, EXISTS,NOT EXISTS 3. 4. Or invalidates the index (you can add an index to each or) 5. Index column function calculation 6. Index operation will invalidate the indexCopy the code
- Do you know the RBAC permission model?
User, Role, menu, user role, Role menu tableCopy the code
- Describe how to implement paging (>7)
Limit the grammarCopy the code
- SQL optimization experience or SQL writing skills (>9k)
You can refer to the appropriate memorization, but nothing is as good as mastering explain grammar. Recommended mastery.Copy the code
- Describe mysql’s two search engines (>9k)
- Difference between clustered and non-clustered indexes (>10)
If you want to understand "clustered index and non-clustered index", you can first look at B tree and B+ tree. Belong to the Innodb. 2. Data is stored in the primary key B+ tree, and data is stored in the child nodes. If there is no primary key, the first column is the clustered index. MyIsam (MyIsam, MyIsam, MyIsam) 2. There is no difference between a normal index and a non-clustered index. 3. The address is stored.Copy the code
- Mysql transaction isolation level (>10)
Read Uncommitted: Dirty reads are allowed, that is, data that may be Read from other sessions with Uncommitted transaction changes. Read Committed: Only data that has been Committed can be Read. Repeated Read: Can be Read repeatedly. All queries within a transaction are at the beginning of the transaction, InnoDB default level. In the SQL standard, this isolation level eliminates non-repeatable reads, but magic reads exist. Serializable: Fully serialized reads. Each read requires a table-level shared lock, and both reads and writes block each other, resulting in the lowest efficiency. Dirty reads, magic reads, and non-repetitive reads can be avoided. The four isolation levels decrease from top to bottomCopy the code
- B +tree (>12k)
Space limited please baiduCopy the code
Again, skills are a must, but small companies don’t go as far as that. Proficiency in writing SQL statements and common grammar are a must. Explain can be said to be a killer in SQL optimization, recommended to understand.
Design patterns
- Say what design patterns you know (in my case, this is usually the end of the story). (> 5)
Expand according to understandingCopy the code
- Describe the factory pattern, agent pattern in detail. (> 7)
Concept: Delegate a proxy class to control another class (the proxy class has objects of the proxy class and can be enhanced in the proxy class) Usage scenario: AOP (can control whether the proxy class is invoked and whether it is propped). Advantages: 1. Ensures the secrecy of the proxied class. 2. Reduced coupling (no need to add methods to enhance each other)Copy the code
Space limited specific please understand
- What design patterns are used in everyday coding (>7)
Agent mode, factory mode, appearance mode, policy mode. Please expand by yourself.Copy the code
- Introduce the appearance mode (>8)
It provides a unified high-level interface for a set of interfaces in a subsystem. This interface makes the subsystem easier to use. (Embodied in services and daOs, a service can call multiple DAOs)Copy the code
- The proxy, decorator, and adapter patterns are the same.
Adapter pattern: The emphasis is on adaptation, and different interfaces can be called without inheritance. Proxy pattern: the main emphasis is on control. The class being proxyed may not necessarily perform and may not be allowed to be proxyed. Decorator pattern: The main emphasis is on enhancement. The purpose is to add the desired decorator to the original class. And the decorator will generally be executedCopy the code
- This section describes the difference between policy mode and state mode. (>10)
This is often asked, so understand the suggestion to study them carefully: https://www.zhihu.com/question/23693088Copy the code
Design patterns are not often used in everyday use, but there are some basics that need to be understood to broaden your perspective. Now is the time to learn about the interview.
mybatis
- #{} = %{}
{} is precompiled processing, and ${} is string substitution. Mybatis will replace #{} in SQL with? Number, which is assigned by calling the set method in PreparedStatement; When Mybatis processes ${}, it replaces ${} with the value of the variable. Using #{} can effectively prevent SQL injection, improve the security of the systemCopy the code
- SQL Injection (>5)
SELECT * FROM Users WHERE username= 'or 1=1 AND password=' or 1=1; SELECT * FROM Users WHERE username= 'or 1=1 AND password=' or 1=1;Copy the code
- Talk about common tags (>5)
Foreach, where, if, SQL, set, include, SQL, choose, curd is not much saidCopy the code
- Mysql > add primary key (>6)
We'll add keyProperty="id" useGeneratedKeys="true"Copy the code
- Mybatis level-1 cache and Level-2 cache (>7)
Level 1 cache is automatically enabled. Is the sqlSession level cache. The level 2 cache is at the Mapper level and can be used whenever a call is made to a single mapper.Copy the code
- Mybatis (>9)
A long story, please baidu.Copy the code
Required skills, but focus on the basics above. You can increase the difficulty depending on your salary.
distributed
- Introduction to distribution and understanding of distribution (>5)
Distributed will focus on a system is divided into several business units, such as a portal site may have a login, video, pictures, etc., each of which can be split to deploy independently, and each one can make it into a cluster, and video services cluster, photo service clusters, the primary system can be to call these subsystems, There may or may not be an invocation relationship between subsystems, depending on the actual business situation. There are many online, please summarize yourselfCopy the code
- Distributed transactions (>10)
TCC, SEATA, etcCopy the code
- Distributed locking (>10)
Redission, etc., please check by yourselfCopy the code
Distributed transactions, distributed locks and other small companies are not used much, elementary, intermediate understanding, if you want to get a higher salary (b) recommended to master.
Spring family bucket (the guy who eats)
spring
- Understanding Spring (>5)
Provides IOC, AOP, for decoupling.Copy the code
- What does Spring mean by dependency injection and Inversion of Control? (>5)
Dependency injection is the same thing as Inversion of Control. Dependency injection: The injected object depends on the IoC container to configure the dependent object. Inversion of Control: Control of the bean is given to the factory.Copy the code
- What are the advantages of Spring over new() (>6)
2. Save heap memoryCopy the code
- Implementation of IOC and AOP (>7)
Ioc factory pattern AOP proxy pattern involves source code, space limited please baiduCopy the code
- Say you know why Spring injection failed (>6)
2. Name the bean set or get(other keywords may also be problematic) 3. Circular dependenciesCopy the code
- Can you introduce spring’s circular dependencies? (>10)
Circular dependencies are essentially circular references, where two or more beans hold each other, resulting in a closed loop. For example, A depends on B, B depends on C, and C depends on ACopy the code
- Spring’s transaction propagation level (>10)
PROPAGATION_REQUIRED - Supports the current transaction and creates a new transaction if none exists. This is the most common choice. PROPAGATION_SUPPORTS - Supports the current transaction, if no current transaction exists, execute non-transactionally. PROPAGATION_MANDATORY - Supports the current transaction, throws an exception if there is no current transaction. PROPAGATION_REQUIRES_NEW - Create a new transaction and suspend the current transaction if one exists. PROPAGATION_NOT_SUPPORTED - Perform the operation in a non-transactional manner, suspending the current transaction if one exists. PROPAGATION_NEVER - Execute non-transactionally, throw an exception if a transaction currently exists.Copy the code
- Bean initialization process (>10)
Involving source code, space is limited, please baidu.Copy the code
spring cloud
- Have you ever used microservices? Explain your understanding of microservices (>5)
1. Split services by business to facilitate management and development. 2. More convenient cluster construction. 3. Easier container construction.Copy the code
- Which microservice components have been used in the project (>6) (based on different microservice ecology)
Netflix and Daddy Eco need to know oneCopy the code
- How to select the components of a microservice ecosystem (>7)
Recommended selection of dad version registration and configuration: NACOS inter-service invocation: Dubbo/Openfeign gateway: Getway monitoring: Sentinel Advantage 1. Nacos is more powerful than Eureka, with namespaces, groups, etc. 3. Superior performance. 4. Complete Chinese documents.Copy the code
- Gateway Understanding (>7)
In the absence of API gateway as a unified export, the need to combine a variety of services, the caller yourself and easy to make the caller feel the existence of the back-end services, after joining the gateway and the client invokes the service shall be carried out through the gateway, and the gateway can handle routing, security, current limiting, caching, logging, monitoring, retry, fuse, etc, Make business development cleaner.Copy the code
- Talk about the understanding of circuit breaker (>7)
Due to network reasons or its own reasons, the service cannot be guaranteed to be 100% available. If a single service has problems, thread blockage will occur when invoking this service. At this time, if a large number of requests flood in, thread resources of the Servlet container will be consumed, leading to service paralysis. The dependency between services will spread and cause catastrophic consequences to the entire microservice system, which is the "avalanche" effect of service failure. In order to solve this problem, the industry put forward the fuse model.Copy the code
- The process of registering and exposing services in a microservice system (>8)
The service sends a request to the registry, and the registry obtains the service information and saves it locally. When the service needs to be invoked between services, the service will pull the list of services in the registry, obtain the information of the invoked service, and perform the invocation. And there is the concept of a heartbeat, and a fixed amount of time that a service sends a request to the registry to indicate that it is alive.Copy the code
- What if there is no response due to slow response time for inter-service invocation (>9)
You can increase the amount of time the call allows to stay connected, but slow response times are particularly bad for the user experience, so it is not recommended. Therefore, the following steps are required: 1. Check whether the called server has room for optimization, such as SQL. 2. For a small number of requests, add circuit breaker to improve user experience; 3. If allowed, use asynchronous or MQ. Get data in an asynchronous manner.Copy the code
Spring MVC (if so)
- How spring MVC works (>7)
(1) The client (browser) sends the request directly to the DispatcherServlet. (2) The DispatcherServlet calls HandlerMapping according to the request information and resolves the Handler corresponding to the request. (3) After parsing to the corresponding Handler, it begins to be processed by the HandlerAdapter. (4) The HandlerAdapter will call the real Handler according to the Handler to open processing request, and handle the corresponding business logic. (5) After processing the business, the processor will return a ModelAndView object, Model is the returned data object, View is a logical View. (6) The ViewResolver will find the actual View according to the logical View. (7) DispaterServlet passes the returned Model to the View. (8) Through the View to return to the requestor (browser) for detailed answers, please baiduCopy the code
- Introduction to DispatchServlet (>8)
1. The request is first sent to the DispatchServlet, which is spring's pre-servlet, which receives the request and forwards it to Spring's MVC Controller. The DispatchServlet uses HandlerMapping to determine which controller to forward the request to. 3. After DispatchServlet forwards the request to the identified controller, the DispatchServlet offloads the request, and the controller handles the request. The business logic is usually handled by invoking the Service layer 4. When the controller finishes processing the request, it encapsulates the result of the business process into a model. To make the model better displayed on the page, the Controller also specifies the view corresponding to the model (such as a JSP page). When the controller determines the Model and view, The DispatchServlet finds the page corresponding to the view by querying the ViewResolver. 6. The DispatchServlet finally delivers the Model to the page for rendering 7. The page renders the Model, presents the results to the client, and the request endsCopy the code
- Talk about understanding the context (>8)
The context is the container that holds all the resources of the application, and you access them when you need them, so everything in the context, within the same application, is global; A Web context can be thought of as the environment in which a Web application is run. It is usually decorated with the name of the context, which contains some Settings and global variables related to the Web applicationCopy the code
- The difference between Spring Boot and Spring Boot (>10)
Spring MVC requires a lot of XML configuration, while Spring Boot adheres to conventions rather than configurations. See below for springBoot implementationCopy the code
spring boot
- How to annotate an interface (>5)
@RestController, @RequestMapping,@RequestParam, @Service,@RequestBody, @RequestMapping, etcCopy the code
- Spring Boot Transactions (>5)
In an interface, all data processing is completed or processing fails, preventing part of the failure and part of the success. Use @Transactional(rollbackFor = exception.class)Copy the code
- Describe the restful style (>7)
A software architectural style, design style, adding, deleting, modifying and querying interfaces using a single name, using the request type (GET, POST, PUT, DELETE) to determine which interface to call.Copy the code
- How springBoot starts (>8)
1. Run SpringApplication. The run () method (2) SpringApplicationRunListeners listeners = this. GetRunListeners (args); Starting () triggers applicationStartedEvent to start listener 4. The environment to trigger applicationEnvironmentPrepareEvent 5 ready to environment. Create a Spring context createApplicationContext() 6. Initialize the context: 1) 2) get to start the class package address: to BeanDefinitionRegistry 3) : Through annotation scanning bean (4) : call BeanDefinitionReaderUtils. RegisterBeanDefinition (definitionHolder, enclosing registry); Register the launch class BeanDefinition with the IoC container's beanDefinitionMap 7. The following is the bean life cycle!! Key) // Set the BeanFactory post processing. Empty method, left for subclass expansion. (1) postProcessBeanFactory (the beanFactory); / / call the BeanFactory post-processor, after the processor is registered in the Bean definition to the container. (2) invokeBeanFactoryPostProcessors (the BeanFactory); (3) automation configuration / / registered Bean after the processor, in the process of Bean creation calls. (4) registerBeanPostProcessors (the beanFactory); // initMessageSource(); // initMessageSource(); / / initialization ApplicationEventMulticaster bean, application events radio device (6) initApplicationEventMulticaster (); // Initialize other special beans. Empty methods are left for subclass expansion. (7) onRefresh (); // Check and register the listener Bean with the container (8) registerListeners(); / / instantiate all the rest of the (non - lazy - init) singleton Bean. (9) finishBeanFactoryInitialization (the beanFactory); // Publish the container event to end the refresh process. 7.ApplicationRunner and CommandLineRunner startCopy the code
- How Spring Boot implements conventions over configurations (>8)
Involving source code, please baidu.Copy the code
- Describe asynchrony in Spring Boot (>8)
The Async annotation takes effect after the call immediately returns the fixed object, releases the thread, and the program executes in the background. The foreground does not perceive.Copy the code
- Describe how cross-domain is handled (>8)
The CORS configuration is added. Specify a background address to allow access.Copy the code
- Introducing custom annotations (>9)
1. Aop based 2. Interceptor 3Copy the code
- @Resource and @autowired (>9)
The @autowired annotation is provided by Spring and is injected as byType only; The @resource annotation is provided by J2EE and automatically injected by byName by default. 2. @autowired is assembled by type by default, and @resource is assembled byName by default.Copy the code
For a small company, the skill requirement is really not much, data structure algorithm, not at all, so the most important is the use of SpringBoot, if you can proficiently write interface, proficient in SSH, then it is not difficult to find a dream job. Therefore, the SpringBoot interface must be written 6.
spring security
- Describe spring Security and describe each of the following (>7)
Authentication and authentication. Authentication: Verifies whether the password is correct. Authentication: verifies whether the user has the permission to access the interface.Copy the code
- Spring Security Token storage mode (>7)
Memory, database, Redis, JWTCopy the code
- What’s the difference between JWT and Redis storage (>8)
JWT can only verify, but cannot delete or modify the token. If you need to kick people or operate the token, please select Redis.Copy the code
- Describe the Spring Security core configuration class (>8)
- Spring Security (>9)
It's a bunch of chains of filters, individually validatedCopy the code
- How to implement verification code function (>9)
- Remember how my function works (>9)
In small companies spring Security + Oauth2 talent is really small, so learn old iron. If you want to become a part of your company’s architecture in the future, or are dissatisfied with Curd, Spring Security should be worth your while.
The middleware
elasticsearch
- A brief introduction to ES (if included)
Elasticsearch is an open source distributed, RESTful search and data analysis engine based on the open source library Apache Lucene. And has the following characteristics: 1. Distributed real-time file storage, and every field is indexed, so that it can be searched. 2. Distributed search engine for real-time analysis. 3. Can scale to hundreds of servers to handle petabytes of structured or unstructured data.Copy the code
- Describe the inverted index for ES (>6)
By recording which documents each term appears in and where it appears in the documents, you can quickly locate the document containing the term and where it appearsCopy the code
- Select * from ‘es’ where’ es’ = ‘es’; select * from’ es’ where ‘es’ =’ es’; select * from ‘es’ where’ es’ = ‘es’ where’ es’ = ‘es’;
GET /20211201-logs/_search
{
"query": { "match_all": {}
}
Copy the code
- What is the scenario that es uses (>7)
Full text search, Precision query, ELK, etcCopy the code
- What clients are used in Spring Boot Integration (>7)
Spring provides ElasticsearchTemplate for simple applications and RestClient for complex applicationsCopy the code
- Query for indexes with the same prefix (>8)
GET /*_logs/_search
{
"query": { "match_all": {}
}
Copy the code
Use very little, there is written we have to ask ah. It’s not necessary.
rabbitmq
- What does MQ do (>5)
Peak clipping, asynchronous, decoupledCopy the code
- Rabbitmq Usage Scenarios (>6)
Send a large number of requests to other servers asynchronously and slowly pull the appropriate amount of requests according to the server performanceCopy the code
- What types of switches (>7)
Fanout: Sends it to all queues bound to the switch. Direct: The default exchange method, which searches for the queue according to the key provided. If the key is A, data can only be sent to A's queue. Topic: Fuzzy matching, as long as it conforms to the format. There can be two types of special characters "*" and "#" for fuzzy matching, where "*" is used to match one word and "#" is used to match multiple words (it can be zero). For example, *.c. # matches A.C.B. but not A.B.C. (which is associated with banding key). Head: Matches the headers attribute in the message content.Copy the code
- How to ensure that messages are not lost (>8)
1: queue persistence disk 2: manual ACK 3: confirm whether the message is sent successfully 4: cluster processing 5: remote Dr 6: The message is persisted to the DB for resend 7: The consumer message is sent to the DB to check whether the message is reused based on the message IDCopy the code
- Talk about the ACK and the Nack
Manually answer whether the queue is received successfully. Otherwise, consumers will always occupy the queueCopy the code
- Know about delay queues and dead letter queues (>10)
Dead letter queue: If there is an error message, if you manually nack the message and put it back on the queue, the message will be consumed repeatedly and stay in the queue. If you nack the message and then drop it, the message will also be lost if you encounter network jitter. So establish a dead letter queue to avoid message loss. Delayed queue: Execution is triggered after certain conditionsCopy the code
Mq is also used less in small companies, but it is strongly recommended that you do not ask if you do not write, but if you use it, you must ensure the accuracy of the message to a certain extent, such as to prevent the long-term use of a queue, the message is not consumed.
redis
- Use scenarios for Redis (>5)
Use an automatic expiration policy to store token hotspot data. Redis uses an atomic self-incrementing counter to store distributed locksCopy the code
- Why Redis is faster than database (>6)
One. Pure memory operation two. Instead, a single thread avoids the frequent context switching problems of multiple threadsCopy the code
- Redis5 basic data types (>6)
string,list,map,set,zset
Copy the code
- Redis Avalanche penetration (>8)
- Avalanche penetration solutions (>9)
A cache avalanche: a large number of keys fail at the same time, and a large number of requests are sent to the DB, resulting in db downtime. Cache penetration: A large number of requests for a key that is not in the cache are directed to the DB, causing an outage. For example, when sending an incoming parameter with a negative number. The solution is as follows: 1. Add authentication to prevent unauthorized entry. 2. Nginx adds interception to prevent a large number of requests from the same IP address. 3. Use the Bloom filter to check whether the database exists. Cache breakdown: The hotspot key suddenly fails, a large number of requests are sent to db, and DB breaks down. Solution: 1: Set the hotspot cache to not expire. 2: add the mutexCopy the code
- Why is redis single-threaded so fast? (>10)
One. Pure memory operation two. The core is based on non-blocking I/O multiplexing mechanism 3. Instead, a single thread avoids the frequent context switching problems of multiple threadsCopy the code
- Redis persistence (>10)
RDB: RDB implements full mirroring persistence and saves all redis data in binary format. RDB takes a long time and is not real-time enough, resulting in a large amount of data loss during downtime. It starts the subthread at intervals and persists the data during this period. AOF: Incremental persistence that saves the current second or instruction as textCopy the code
- How to resolve redis data consistency with database (>12)
First delete the cache, then update the database, and then double delete consistencyCopy the code
The most commonly used middleware, recommended must master. Small companies use most of the background is to use key expiration time to save tokens, or use redis atomicity, counting use, there may be a small amount of consideration from relieving database pressure. So a few questions after the application of very little, but, this kind of commonly used in the middle price should be back before the interview.
Mycat (Resume ask again)
- What environment to use Mycat (>5)
- Background of sub-table (>5)
- Whether the current environment is suitable for sub-table
- Mycat principle (> 7)
- How to query, paging, sorting (>8)
Rarely used, the main building has not applied experience, but the resume has written or will ask. There are no lessons here. There’s no need to memorize.
Code specification
- What is the shortcut key for idea formatting code (>5)
ctrl+alt+l
Copy the code
- Whether to establish an interface specification for an interface written by yourself (>7)
It is recommended to understand the Ali specificationCopy the code
- Whether to create a specification for your own tables (>7)
It is recommended to understand the Ali specificationCopy the code
- Whether or not to standardize your own code (>7)(>7)
It is recommended to understand the Ali specificationCopy the code
- How often do you write classes and comments? (>7)
It is recommended to understand the Ali specificationCopy the code
- Whether there are plug-ins or their own system checks for the specification
It is recommended to know ali P3CCopy the code
- What interface document to use, and what to note in it.
For me, a good writing habit is an essential quality of a good programmer, whether in daily writing or as a teamleader or manager in the future, it is definitely needed. Otherwise, how to install B with little brother, here I will focus on asking, unfortunately, to meet the requirements of very few. I feel that if I highlight my experience during the interview, I will stand out.
multithreading
- How to understand Multithreading (>5)
If you don't use multiple threads to do one thing before you can do another, you can't comment while listening to a song and only the thread that is listening to it is executing. Instead, if you use multiple threads, you can comment while listening to a song and increase memory usage to avoid idle memory (but you can't create too many threads, it will slow down).Copy the code
- Describe the thread state (>8)
When a Thread object is created with the new keyword and class Thread or a subclass, the Thread object is in the new state. It stays in this state until the program starts () the thread. Ready state: When the thread object calls the start() method, the thread enters the ready state. Threads in the ready state are in the ready queue, waiting to be scheduled by the THREAD scheduler in the JVM. Running state: If a thread in the ready state acquires CPU resources, it can execute run() and the thread is in a running state. A running thread is the most complex and can become blocked, ready, and dead. Blocked: If a thread executes methods such as sleep or suspend and loses resources, it enters the blocked state from the running state. You can re-enter the ready state after sleep time has reached or device resources have been obtained. There are three types: Wait block: A running thread executes the wait() method to put the thread into wait block state. Synchronization block: A thread failed to acquire the synchronized lock because the lock was occupied by another thread. Other blocking: When I/O requests are made by calling the thread's sleep() or join(), the thread is blocked. When the sleep() state is out, join() waits until the thread terminates or times out, or the I/O processing is complete and the thread returns to the ready state. (Note that sleep does not release a held lock.) Dead state: When a running thread completes a task or another termination condition occurs, the thread switches to the terminated state.Copy the code
- Introducing thread pools (>8)
Java has developed a concept for managing threads, called thread pools, that has the following advantages: (1) Reduced resource consumption. Reduce the cost of thread creation and destruction by reusing threads that have been created. (2) Improve the response speed. When a task arrives, it can be executed immediately without having to wait for the thread to be created. (3) Improve thread manageability. Threads are scarce resources. If they are created without limit, they will not only consume system resources, but also reduce system stability. Thread pools can be used for uniform allocation, tuning, and monitoring.Copy the code
- What is thread safe? Introduce several classes or methods in Java that are thread unsafe (>8)
If you execute the thread multiple times, the result doesn't change, then thread-safe StringBuilder, SimpleDateFormat, etcCopy the code
- Why not use the Executors’ four thread pools (>9)
Cause oom, detailed explanation of clear self baidu.Copy the code
- Volatile, ThreadLocal (>10)
Volatile: Ensures visibility when different threads operate on a variable. When one thread changes the value of a variable, the new value is immediately visible to other threads. Only atomicity is guaranteed for a single read/write. I++ does not guarantee atomicity. ThreadLocal: ThreadLocal provides a separate copy of a local variable (which is essentially a Map) for each thread that uses the variable, so each thread can change its own copy independently, limiting the visibility of the object to the same thread without affecting the corresponding copies of other threads. This is essentially a space-for-time approach (as opposed to synchronized) that significantly reduces the performance costs associated with thread synchronization (such as synchronized) and the complexity of thread concurrency control at the expense of memory.Copy the code
- Introducing locks (>12)
Many types, space reasons, please baidu.Copy the code
Multithreading is less commonly used by small companies in general. Just understand. Or ask but use less.
algorithm
Bubble sort the world! You know!Copy the code
conclusion
- Spring basic concepts and simple principles need to be mastered.
- Spring Boot interface must be written 6, very very slip. The guy who eats.
- In the process of interface writing, often used Java basic to be familiar with, such as numerical comparison, collection class processing.
- Knowledge of Redis middleware is essential, and knowledge of RabbitMQ is recommended.
- At least master the interview questions above. If you are good at explain grammar, this will kill most competitors.
- Spring Cloud suggests mastery of an ecology, and suggests a daddy version, which is a plus.
- Spring Security and code specification building is a great skill to highlight a level difference from others. Spring Security may take time, but the specification can be rigorously developed on a daily basis. Plus.
- Do not have to master the other, but all can install X.