2018 Java technology interview questions sorting

1. Servlet execution process

The client sends an HTTP request, and the web server forwards the request to the servlet container, which parses the URL according to the web XML finds the corresponding servlet and passes the request and response objects to the found servlet. The servlet can know who sent the request, request information and other information according to the request. When the servlet processes the business logic, it will put the information into the response and respond to the client.

2. Execution process of spring MVC

Spring MVC is a hierarchical control framework with dispatch servlet as the core. First, the client sends a request. The web server parses the request URL and matches the mapping URL of the dispatchservlet. If it matches, it puts the request into the dispatchservlet. The dispatchservlet looks for the corresponding Handel according to the mapping configuration, and then gives the processing power to the found Handel. The Handel encapsulates the code for processing business logic, After Handel processing, it will return a logical view modelandview to the dispatchservlet. At this time, the modelandview is a logical view, not a formal view, so the dispatchservlet will parse the modelandview through the viewresource view resource, and then put the parsed parameters into the view, return them to the client and display them.

3. Given a TXT file, how to get the number of occurrences of a string

4. Java design pattern idea (single column pattern, factory pattern, policy pattern, a total of 23 design patterns)

a) Singleton mode: the core of singleton mode only needs a new instance object mode, such as database connection, online number, etc. the online number statistics seen on some websites are realized through singleton mode. A timer is stored in the database or memory. When someone logs in, it is taken out and put back again and again, When someone logs out, the counter will be taken out at the same time, one will be added at the same time, and the data will be put back at the same time. In this way, the data will be wrong. Therefore, an object of global variable needs to be used by all people, and only an instance object needs to be new. This is the application of singleton mode, Moreover, the 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 and ensure the portability and maintainability of the code. For example, there is a requirement to write duck objects. Ducks have three methods: call, fly and shape. If each duck class writes these three methods, there will be code redundancy. At this time, we can extract the three methods of call, fly and shape from ducks and put them into the duck parent class. Let each duck inherit the duck parent class and rewrite these three methods, This encapsulated code has strong portability. When users put forward new requirements, such as ducks can swim, it is very simple for our OO programmers. We just need to add a swimming method to the duck parent class and let the swimming ducks rewrite the swimming method.

c) Factory mode: simple factory mode is mainly to provide references to instance objects uniformly, and obtain references to instance objects through the factory mode interface. For example, for a login function, the back end has three classes, controller class, interface class and implementation class to implement the interface. When the client sends a request, when the request is passed to the controller class, the controller obtains the reference object of the interface, and the implementation class implementing the interface encapsulates the login business logic code. When you need to add a registration requirement, you only need to add a registration method in 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 method has strong expansibility.

5. Bubble sort, binary search

a) Bubbling

b) Binary search

6-8. Understanding of Ajax

a) AJAX is an asynchronous request, that is, local refresh technology. In traditional pages, users need to click a button or event to trigger a request to refresh the page, while asynchronous technology can trigger an event without clicking, which enhances the user experience. For example, the asynchronous loading of shopping carts in shopping malls can directly and dynamically modify parameters without requesting the background when you click on goods.

9. Call order between parent and child classes (print results)

a) Parent static code block

b) Subclass static code block

c) Parent class construction method

d) Subclass construction method

e) Subclass general method

f) If the method of the parent class is overridden, the overridden method is printed

10. Calls to inner and outer classes

a) Internal classes can directly call external classes, including private member variables, and use this. Referenced by external classes Keyword call

b) When an external class calls an internal class, an internal class object needs to be established

11. Multithreading

a) A process is an independent running environment, which can be regarded as a program, and a thread can be regarded as a task of the process. For example, QQ is a process, and a QQ window is a thread.

b) In a multithreaded program, multithreading concurrency can improve the efficiency of the program. CPU will not enter the idle state because a thread is waiting for resources. It will give resources to other threads.

c) The user thread is the thread created by our development 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 a limited high level can first obtain CPU resources to turn 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. If deadlock is avoided, nested locks are avoided. They only need to lock where they need to be synchronized and avoid infinite waiting

12. The concept of AOP and IOC (the core of spring)

a) IOC: spring is an open source framework. Using the framework 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 aspect oriented programming. IOC control inversion mainly emphasizes that the relationship between programs is controlled by containers. Containers control objects and control the acquisition of external resources. Inversion means that in traditional programming, we create objects to obtain dependent objects. In IOC, the container helps us create objects and inject dependent objects. It is the container that helps us find and inject objects. Objects are obtained, so it is called inversion.

b) AOP: aspect oriented programming, which mainly manages the business of the system layer, such as logs, permissions, things, etc. AOP is to dissect the encapsulated objects, find out the common behaviors that affect multiple objects, and encapsulate them into a reusable module, This module is named aspect, which extracts and encapsulates the logic that has nothing to do with the business logic but is called by the business modules, reduces the repeated code in the system, reduces the coupling between modules, and improves the maintainability of the system.

13. The core idea of Hibernate

a) The core idea of Hibernate is ROM object relational mapping mechanism. It maps operations between tables to 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 map the data table entity class so that the modification of the object corresponds to the modification of the data row.

14. The difference between struts 1 and struts 2

15. Delete a character in a string

16-17. Differences between ArrayList and LinkedList

a) Both are lists that implement the list interface. ArrayList is an array based data structure, and LinkedList is a linked list based data structure. When obtaining specific elements, ArrayList is more efficient. It can be obtained through the array subscript, while LinkedList needs to move the pointer. When storing and deleting elements, LinkedList is efficient. You only need to move the pointer to a specified position to add or delete, while ArrayList needs to move data.

18. Database optimization

a) Select an appropriate field. For example, the mailbox field can be set to char (6), and try to set the field to not null, so that the database does not need to compare null values during query

b) Use a left join on query instead of a subquery

c) Manually create temporary tables using union join queries

d) Open the transaction. When errors occur in the execution of multiple statements in the database, the transaction will be rolled back, which can maintain the integrity of the database

e) Using foreign keys, things can maintain the integrity of data, but it can not ensure the relevance of data. Using foreign keys can ensure the relevance of data

f) Using index is a common method to improve database performance. It can make the database server retrieve specific rows much faster than without index, especially for max, min and order by queries

g) For optimized query statements, in most cases, the use of index can improve the speed of query, but if SQL statements are not used properly, the index can not 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 number optimization: the concurrent connection parameters of tomcat, mainly in the Tomcat configuration file server XML, such as modifying the minimum number of idle connection threads to improve system processing performance, etc.

c) Optimize cache: open the compression function and modify parameters. For example, the size of compressed output content is 2KB by default, which can be modified appropriately.

20. HTTP protocol

a) The common request methods are get and post

b) The difference between get and post: when data is transmitted, get carries parameters and access addresses for transmission, which can be seen by the user. In this case, the information will be unsafe and lead to information disclosure. Post encapsulates the field and corresponding value in the entity, which is invisible to the user. The parameters passed by get are limited, while post is unlimited.

21. TCP / UDP protocol

22. What are the basic interfaces of the Java collection class framework

a) Collection collection interface, list and set implement collection interface, ArrayList and LinkedList, vector implement list interface, stack inherit vector and map interface, hashtable and HashMap implement map interface

23. Class loading process

a) When a new class is encountered, it will first go to the method area to find the class file. If it is not found, it will go to the hard disk to find the class file. After finding it, it will return and load the class file into the method area. When the class is loaded, the static member variables will be assigned to the static area of the method area and the non-static member variables will be assigned to the non-static area, Then initialize the static member variable and assign the default value. After assigning the default value, the display value will be assigned according to the writing position of the static member variable, and then execute the static code. When all static code is executed, class loading is completed.

24. Creation of objects

a) When a new class is encountered, the class will be loaded and located in the class file

b) When all static member variables are initialized, the static code block will also be executed, and only once when the class is loaded

c) New object, the JVM allocates a large enough storage space in the heap

d) Empty the storage space, assign default values to all variables, and assign null to all object references

e) Initialize the field according to the writing position

f) Call constructor method (no inheritance)

25. JVM optimization

a) Set parameters to set the maximum memory of the JVM

b) Selection of garbage collector

26. High concurrency processing

a) Understand the problem of high concurrency. For example, 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 synchronization is a lock. Synchronization can only be performed by one person at a time. At this time, the lock mechanism can be used, and the optimistic lock 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 not only ensures the readability of data, but also ensures the exclusivity of saved data, and solves the problem of dirty data reading caused by concurrency while ensuring performance.

27. Understanding of things

a) Things have atomicity, consistency, persistence and isolation

b) Atomicity: it means that in a thing, either all execution is successful or all failures are rolled back.

c) Consistency: things are in a consistent state before and after execution

d) Persistence: the operation of multiple data 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 sends a request to the servlet container

b) The request is called by the filterdispatcher after some column filtering. The filterdispatch finds the corresponding action through actionmapper.

c) Actionmapper finds the corresponding action and returns it to filterdispatch, which gives the processing right to actionproxy

d) Actionproxy finds the corresponding action class through the configuration file

e) Actionproxy creates an instance of actioniinvocation to handle business logic

f) Once the action is processed, the actioninvocation is responsible for the processing according to stuts The corresponding return result is found according to the configuration of XML. The returned result is usually a JSP page.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>