The following interview questions are what individuals encounter during the interview process and are for reference only! If there is any error, please point it out.
Technical exchange group: 365814763
1、servlet execution process
The client issues an http request, and the web server forwards the request to the servlet container. The servlet container parses the url and finds the corresponding servlet, and passes the request and response objects to the found servlet. The servlet can know who issued the request, request information and other information based on the request. After the servlet has processed the business logic, it will put the information into the response and respond to the client.
2、SpringMVC execution process
springMVC is a hierarchical control framework with dispatchservlet as the core. First, the client issues a request to the web server to parse the request url and match the mapping url of the dispatchservlet. If it matches, put this request into the dispatchservlet. The dispatchservlet searches for the corresponding handle according to the mapping mapping configuration, and then hand over the processing rights to the found handle. The handle encapsulates the code for processing business logic. After the handle is processed, it will return a logical view modelview to the dispatchservlet. At this time, the modelview is a logical view, not a formal view, so the dispatchservlet will parse the modelview through the viewresource view resource, and then put the parsed parameters into the view and return to the client and display it.
3、Given a txt file, how to get the number of times a certain string appears
File file = new File("E://");
InputStream is = new FileInputStream(file);
byte b[] = new byte[1024];
int a = is.read(b);
String str[] = new String(b,0,a).split("");
int count = 0;
for(int i = 0;i<str.length;i++){
if("a".equals(str[i]))count++;
}
System.out.println(count);
4、Java design pattern ideas (single-column mode, factory mode, strategy mode, a total of 23 design patterns)
a) Singleton mode: The core of singleton mode only requires new one instance object mode, such as database connection, number of online people, etc. The online number statistics seen on some websites are implemented through singleton mode, which stores a timer in the database or memory. When someone logs in, adds it and puts it back again and again. When someone logs out, take it out and subtracts it and puts it back again and again. However, when two people log in at the same time, they will take out the counter at the same time, add one and put it back at the same time. In this way, the data will be wrong. Therefore, an object of global variable is needed for all people to use, and only one instance object is needed. This is the application of singleton mode, and singleton mode saves resources because it controls the number of instance objects and is conducive to gc recycling.
b) Policy pattern: It is to extract the common methods in several classes into a new class, so as to make the extension easier, ensure the portability of the code, and have strong maintenance. For example, there is a requirement to write duck objects, which are called, fly, and appearance. If each duck class writes these three methods, the code will be redundant. At this time, we can extract the three methods called, fly, and appearance in the duck class, and put them into the duck parent class, so that each duck inherits the duck parent class and rewrites these three methods. In this way, the encapsulated code is highly portable. When the user proposes new requirements such as the duck can swim, it is very simple for us oo programmers. We only need to add a swimming method to the duck parent class, and let the swimming duck rewrite the swimming method.
c) Factory mode: The simple factory mode mainly provides references to instance objects in a unified manner and obtains references to instance objects through the factory mode interface. For example, for a login function, the backend has three classes, controller class, interface class, and implementation class of the implementation interface. When the client issues a request, when the request is passed to the controller class, the controller obtains the reference object of the interface, and the implementation class implements the interface encapsulates the login business logic code. When you need to add a registration requirement, you only need to add a registration method to the interface class, implement the method in the implementation class, and the controller can obtain the reference object of the interface without changing the original code. This approach is highly scalable.
5、Bubble sorting, binary search
a) Bubble
public static void mp(int a[]) {
int swap = 0;
for (int i = 0; i < a.length; i++) {
for (int j = i; j < a.length; j++) {
if (a[j] > a[i]) {
swap = a[i];
a[i] = a[j];
a[j] = swap;
}
}
}
System.out.println(Arrays.toString(a));
}
b) Binary searchpublic static int ef(int a[], int tag) {
int first = 0;
int end = a.length;
for (int i = 0; i < a.length; i++) {
int middle = (first + end) / 2;
if (tag == a[middle]) {
return middle;
}
if (tag > a[middle]) {
first = middle + 1;
}
if (tag < a[middle]) {
end = middle - 1;
}
}
return 0;
}
6、Understanding of ajax
a) Ajax is an asynchronous request, that is, a local refresh technology. In traditional pages, users need to click on buttons or events to trigger requests to refresh pages, while asynchronous technology triggers events without clicking, which enhances the user experience, such as asynchronous loading of shopping carts in the mall, when you click on a product, you don’t need to request the background and directly modify parameters dynamically.
9、The order of call between parent class and child class (print result)
a) Parent class static code block
b) Subclass static code block
c) Parent class constructor
d) Subclass construction method
e) Subclass ordinary method
f) Rewrite the method of the parent class, print the rewrite method
10、Calls of inner and outer classes
a) The inner class can directly call the member variables of the external class including private, and use this. keyword referenced by the external class to call it
b) When an external class calls an internal class, it is necessary to establish an internal class object
11、Multi-threaded
a) A process is an independent running environment, which can be regarded as a program, while a thread can be regarded as a task of a process. For example, QQ is a process, and a QQ window is a thread.
b) In a multi-threaded program, multi-threaded concurrency can improve the efficiency of the program. CPU will not enter an idle state because a certain thread is waiting for resources. It will give resources to other threads.
c) User thread is the thread that we develop the program, and the daemon thread is the system thread, such as GC in JVM virtual
d) Thread priority: Each thread has a priority level. Those with high finite level can first obtain CPU resources to change the thread from ready state to running state. You can also customize the limited level of threads
e) Deadlock: At least two or more threads strive for more than two CPU resources, avoid using nested locks if they avoid deadlocks. You only need to add locks where they need to synchronize and avoid infinite waiting.
12、The concept of AOP and IOC (i.e. the core of spring)
a) IOC: Spring is an open source framework. Using frameworks can reduce our workload and improve our work efficiency. It is a hierarchical structure, that is, the corresponding layers process the corresponding business logic and reduce the coupling degree of code. The core of spring is IOC control inversion and AOP-oriented tangential programming. IOC control inversion mainly emphasizes that the relationship between programs is controlled by containers, which controls objects and controls the acquisition of external resources. Inversion means that in traditional programming, we create objects to obtain dependencies, while in IOC, the container helps us create objects and inject dependent objects. It is the container helps us find and inject objects. The object is obtained, so it is called inversion.
b) AOP: Oriented programming, mainly manages the business at the system level, such as logs, permissions, things, etc. AOP is to cut open the encapsulated objects, find out the common behavior that affects multiple objects, and encapsulate them into a reusable module. This module is named aspect. The section extracts and encapsulates logic that is not related to business logic but is called jointly by business modules, reducing duplicate code in the system, reducing coupling between modules, and improving the maintainability of the system.
13、The core idea of hibernate
a) The core idea of Hibernate is the ROM object relation mapping mechanism. It is a mapping between tables into operations between objects. That is, the information extracted from the database will be automatically encapsulated into specific objects according to the mapping requirements you set. Therefore, hibernate is to modify the object corresponding to the data row by mapping the data table entity class.
14. The difference between Struts1 and Struts2
15、Optimal deletion of a character in a string
16、The difference between Arraylist and linkedlist
a) are all lists that implement list interface. arraylist is an array-based data structure, and linkedlist is a linked list data structure. When obtaining specific elements, ArrayList is relatively fast. It can be obtained through array subscripts, while linkedlist requires moving the pointer. When storing elements and deleting elements, linkedlist is more efficient. You only need to move the pointer to a specified position to add or delete it, while arraylist requires moving data.
17、The difference between mybatis and mybatis
18、Database optimization
a) Select the appropriate field, such as the mailbox field can be set to char(6), and try to set the field to notnull, so that the database does not need to compare the null value when querying
b) Use the left join on query instead of subquery
c) Use union joint query to create temporary tables manually
d) Turn on things. When multiple statements are executed in the database, things will roll back, which can maintain the integrity of the database.
e) Using foreign keys, things can maintain the integrity of data, but they cannot guarantee the correlation of data. Using foreign keys can ensure the correlation of data
f) Use indexes. Indexes are a common method to improve database performance. They can enable database servers to retrieve specific rows much faster than no indexes, especially when queries such as max, min, order by, and the effect is more obvious.
g) Optimized query statements. In most cases, using indexes can improve the speed of query, but if the SQL statement is used inappropriately, the index cannot play its characteristics.
19、Tomcat server optimization (memory, number of concurrent connections, cache)
a) Memory optimization: It mainly optimizes the Tomcat startup parameters. We can modify its maximum memory in the Tomcat startup script, etc.
b) Thread count optimization: Tomcat's concurrent connection parameters are mainly configured in the Tomcat configuration file, such as modifying the minimum number of idle connection threads to improve system processing performance, etc.
c) Optimize cache: Turn on the compression function and modify parameters. For example, the size of the compressed output content is 2KB by default, and it can be modified appropriately.
20、HTTP protocol
a) Commonly used request methods include get and post
b) The difference between Get and post: transfer data, get carries parameters and access address, and users can see it. This will be unsafe and lead to information leakage. Post encapsulates fields and corresponding values in an entity to transmit, which is invisible to the user. There are restrictions on the parameters passing Get, while there are no restrictions on the post.
21、TCP/UDP protocol
22. What are the basic interfaces of Java collection class framework
a) Collection interface, List and set implement Collection interface, arraylist and linkedlist, vector implement list interface, stack inherit vector, Map interface, hashtable and hashmap implement map interface
23、Class loading process
a) When encountering a new class, first go to the method area to find the class file. If it is not found, go to the hard disk to find the class file. After it is found, it will return and load the class file into the method area. When the class is loaded, the static member variable will be assigned to the static area of the method area. The non-static member variable will be assigned to the non-static area. Then, the static member variable will be initialized and assigned to the static member variable. After assigning the default value, the display value will be assigned according to the location written by the static member variable, and then the static code will be executed. Class loading is only completed when all static code is executed.
24、Object creation
a) When a new class is encountered, the class will be loaded and the class file will be located.
b) For all static member variables initialized, the static code block will also be executed, and it will only be executed once when the class is loaded
c) When New object, jvm will allocate a large enough storage space in the heap
d) Clear the storage space, assign default values to all variables, and assign all object references to null
e) Give the field some initialization operations according to the writing position
f) Call the constructor method (no inheritance)
25、Optimization of jvm
a) Set parameters and set the maximum number of memory of jvm
b) The selection of garbage collector
26、High concurrency processing
a) Understand some high concurrency problems, such as when a W person grabs a ticket, how to ensure that everyone can see the ticket without buying it. Obviously, the synchronization mechanism cannot be used, because synchronize is locked and synchronization can only be performed by one person at a time. At this time, the lock mechanism can be used, and using optimistic locking can solve this problem. The simple meaning of optimistic locking is to use business control to solve the concurrency problem without locking the table, which ensures the readability of the data and the exclusivity of the saved data, ensuring performance while solving the dirty reading data problem caused by concurrency.
27、Understanding of things
a) Things are atomic, consistent, durable, and isolated
b) Atomicity: refers to the fact that in a thing, either all execution is successful or all fails to roll back.
c) Consistency: Things are in a consistent state before and after execution
d) Persistence: The operation of multiple data in things is permanent
e) Isolation: When one thing is operating on data, another thing cannot operate on data, that is, multiple concurrent things are isolated from each other.
28. Struts workflow
a) The client issues a request to the servlet container
b) The request is called by the filterdispatcher after some column filtering, and the filterdispatch searches the corresponding action through the actionMapper.
c) Actionmapper finds the corresponding action and returns it to filterdispatch, and dispatch gives the processing rights to actionproxy
d) Actionproxy finds the corresponding action class through the configuration file
e) Actionproxy creates an instance of actionIinvocation to process business logic
f) Once the action is processed, actioninvocation is responsible for finding the corresponding return result according to the configuration. The result is usually a jsp page.
Finally, I wish all programmers a job they like soon
---------------------------------------------------------------------------------------------------------------------
To learn a knowledge, you must first know why it is needed, that is, why the problem arises, and then solve it, and then how to use this knowledge.