Java knowledge points (transfer)

 

1. servlet execution process

The client sends an http request, the web server forwards the request to the servlet container, the servlet container parses the url and finds the corresponding servlet according to web.xml, and passes the request and response objects to the found servlet, and the servlet can know who it is based on the request. The sent request, request information and other information, when the servlet processes the business logic, it will put the information into the response and respond to the client.

 

2. The execution process of springMVC

springMVC is a layered control framework with dispatchservlet as the core. First, the client sends a request to the web server to parse the request url and match the mapping url of the dispatchservlet. If it matches, the request is put into the dispatchservlet. The dispatchservlet searches for the corresponding handel according to the mapping mapping configuration, and then passes the processing power to the finder. The handel, handel encapsulates the code for processing business logic. When the handel is processed, 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 resolve the modelandview through the viewresource view resource. Then put the parsed parameters into the view and return it to the client and display it.

 

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

File file = new File("E://test.txt");

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 pattern, factory pattern, strategy pattern, a total of 23 design patterns)

a) Singleton mode: The core of the singleton mode only needs a new mode of an instance object, such as database connection, online population, etc. The online population statistics seen on some websites are realized through the singleton mode, and a timer is stored in the In the database or memory, when someone logs in, take it out, add one, and put it back. When someone logs out, take it out, subtract one, and put it back. But when two people log in at the same time, the counter will be taken out at the same time, added by one, and put back at the same time. If you go back, the data will be wrong, so you need a global variable object for everyone to use, you only need to create an instance object, this is the application of the singleton pattern, and the singleton pattern saves resources because it controls the instance object. number, and is conducive to GC recovery.

b) Strategy pattern: It is to extract the public methods in several classes into a new class, so as to make the extension easier, ensure the portability of the code, and maintain strong maintainability. For example, there is a requirement to write a duck object. The duck has three methods: call, fly, and shape. If each duck class writes these three methods, there will be code redundancy. At this time, we can call the duck and fly. , the three methods of shape are extracted and placed in the duck parent class, so that each duck inherits the duck parent class and rewrites these three methods, so that the encapsulated code is highly portable. When users put forward new requirements such as Ducks can swim, so 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 the reference of the instance object uniformly, and obtains the reference of the instance object through the factory mode interface. For example, for a login function, there are three classes in the backend, the controller class, the interface class, and the implementation class that implements 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 that 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 scalable powerful.

5, bubble sort, binary search

a) bubbling

  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 search public 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 partial refresh technology. In traditional pages, users need to click a button or an event to trigger a request to refresh the page, while asynchronous technology can trigger events without clicking, which enhances the user experience. For example, the asynchronous loading of the shopping cart in the mall, when you click on the product, you do not need to request the background and directly modify the parameters dynamically.

9. The calling sequence 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 constructor

e) Subclass ordinary methods

f) Override the method of the parent class, then print the overridden method

10. Calls of inner and outer classes

a) The inner class can directly call the member variables of the outer class, including private, by using the this. keyword referenced by the outer class.

b) When the outer class calls the inner class, it needs to create the inner class object

11. Multithreading

a) A process is an independent operating 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 multi-threaded program, multi-threaded concurrency can improve the efficiency of the program. The cpu will not enter an idle state because a thread is waiting for resources, it will give the 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 the GC in the JVM virtual

d) The priority level of the thread: each thread has a priority level, and the one with a higher limited level can obtain CPU resources first to make the thread transition from the ready state to the running state. It is also possible to customize the limited level of threads

e) Deadlock: At least two or more threads strive for more than two cpu resources, to avoid deadlock, avoid using nested locks, 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 a framework can reduce the workload and improve work efficiency. It is a layered structure, that is, the corresponding layer handles the corresponding business logic and reduces the coupling of the code. The core of spring is IOC inversion of control and AOP aspect-oriented programming. IOC control inversion mainly emphasizes that the relationship between programs is controlled by the container, the container controls the object, and controls the acquisition of external resources. The reverse is that in traditional programming, we create objects to obtain dependent objects, while in IOC, the container helps us create objects and inject dependent objects. It is the container that helps us find and inject objects, and objects are acquired. , so it is called inversion.

b) AOP: Aspect-oriented programming, mainly to manage the business of the system layer, such as logs, permissions, things, etc. AOP is to split the encapsulated object, find out the common behavior that affects multiple objects, and encapsulate it into a reusable module, this module is named aspect (aspect), the aspect connects those with business logic Unrelated, but is extracted and encapsulated by the logic commonly called by the business modules, which reduces the repetitive 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 the ROM object-relational mapping mechanism. It maps operations between tables to operations between objects and 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 makes the modification of the object correspond to the modification of the data row by mapping the entity class of the data table.

14. The difference between Struts1 and Struts2

15. Optimal deletion of a character in the string

16. The difference between Arraylist and linkedlist

a) All 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 faster, and it can be obtained by subscripting an array, while linkedlist requires Move the pointer. When storing elements and deleting elements, linkedlist is more efficient, just need to move the pointer to the specified position to add or delete, while arraylist needs to move data.

 

17. The difference between mybaties and ibatise

 

18. Database optimization

a) Select the appropriate field, for example, the mailbox field can be set to char (6), try to set the field to notnull, so that the database does not need to compare null values ​​when querying

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

c) Manually create temporary table using union union query

d) Open the transaction, when the database executes multiple statements and there is an error, 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 cannot guarantee the relevance of data, using foreign keys can ensure the relevance of data

f) Using an index, an index is a common method to improve database performance, it can make the database server retrieve specific rows much faster than no index, especially for max, min, order by queries, the effect is more obvious

g) Optimized query statements. In most cases, the use of indexes can improve the speed of the query, but if the SQL statements are not used properly, the indexes cannot exert their characteristics.

 

19. Tomcat server optimization (memory, concurrent connections, cache)

a) Memory optimization: mainly to optimize the Tomcat startup parameters, we can modify its maximum memory and so on in the Tomcat startup script.

b) Optimization of the number of threads: Tomcat's concurrent connection parameters are mainly configured in server.xml in the Tomcat configuration file, such as modifying the minimum number of idle connection threads to improve system processing performance and so on.

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

 

20. HTTP protocol

a) Commonly used request methods are get, post

b) The difference between Get and post: to transmit data, get carries parameters and access addresses to transmit, and users can see it. In this case, the information will be unsafe, resulting in information leakage. The post encapsulates the fields and corresponding values ​​in the entity, which is invisible to the user. Get has restrictions on passing parameters, while post has no restrictions.

 

21. TCP/UDP protocol

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

a) Collection collection interface, List, set implement Collection interface, arraylist, linkedlist, vector implement list interface, stack inherits vector, Map interface, hashtable, hashmap implement map interface

 

23. The process of class loading

a) When encountering a new class, 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 static member variables are allocated to the static area of ​​the method area, the non-static member variables are allocated to the non-static area, and then the static member variables are initialized and assigned default values. After the default values ​​are assigned, they will be written according to the static member variables. The position is assigned the display value, and then the static code is executed. Class loading is complete 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) All static member variables are initialized, the static code block will also be executed, and only executed once when the class is loaded

c) When a New object is created, the jvm will allocate a large enough storage space in the heap

d) The storage space is cleared, default values ​​are assigned to all variables, and all object references are assigned null

e) Give the field some initialization operations according to the writing position

f) call the constructor method (no inheritance)

 

25. JVM optimization

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

b) Choice of Garbage Collector

 

26. High concurrent processing

a) Know a little about high concurrency issues, such as when one 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 lock synchronization Only one person can do it at a time. At this time, the locking mechanism can be used, and 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 not only ensures the readability of the data, but also ensures the exclusivity of the saved data, guarantees the performance and solves the dirty caused by concurrency. Read data problem.

 

27. Understanding of things

a) Things are atomic, consistent, durable, isolated

b) Atomicity: It means that in a thing, either all executions succeed, or all fail rollbacks.

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

d) Persistence: The operation of multiple data of 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 filterdispatcher after some column filtering, and 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, actioninvocation is responsible for finding the corresponding return result according to the configuration of stuts.xml. The returned result is usually a jsp page.

 

The client sends an http request, the web server forwards the request to the servlet container, the servlet container parses the url and finds the corresponding servlet according to web.xml, and passes the request and response objects to the found servlet, and the servlet can know who it is based on the request. The sent request, request information and other information, when the servlet processes the business logic, it will put the information into the response and respond to the client.

 

2. The execution process of springMVC

springMVC is a layered control framework with dispatchservlet as the core. First, the client sends a request to the web server to parse the request url and match the mapping url of the dispatchservlet. If it matches, the request is put into the dispatchservlet. The dispatchservlet searches for the corresponding handel according to the mapping mapping configuration, and then passes the processing power to the finder. The handel, handel encapsulates the code for processing business logic. When the handel is processed, 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 resolve the modelandview through the viewresource view resource. Then put the parsed parameters into the view and return it to the client and display it.

 

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

File file = new File("E://test.txt");

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 pattern, factory pattern, strategy pattern, a total of 23 design patterns)

a) Singleton mode: The core of the singleton mode only needs a new mode of an instance object, such as database connection, online population, etc. The online population statistics seen on some websites are realized through the singleton mode, and a timer is stored in the In the database or memory, when someone logs in, take it out, add one, and put it back. When someone logs out, take it out, subtract one, and put it back. But when two people log in at the same time, the counter will be taken out at the same time, added by one, and put back at the same time. If you go back, the data will be wrong, so you need a global variable object for everyone to use, you only need to create an instance object, this is the application of the singleton pattern, and the singleton pattern saves resources because it controls the instance object. number, and is conducive to GC recovery.

b) Strategy pattern: It is to extract the public methods in several classes into a new class, so as to make the extension easier, ensure the portability of the code, and maintain strong maintainability. For example, there is a requirement to write a duck object. The duck has three methods: call, fly, and shape. If each duck class writes these three methods, there will be code redundancy. At this time, we can call the duck and fly. , the three methods of shape are extracted and placed in the duck parent class, so that each duck inherits the duck parent class and rewrites these three methods, so that the encapsulated code is highly portable. When users put forward new requirements such as Ducks can swim, so 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 the reference of the instance object uniformly, and obtains the reference of the instance object through the factory mode interface. For example, for a login function, there are three classes in the backend, the controller class, the interface class, and the implementation class that implements 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 that 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 scalable powerful.

5, bubble sort, binary search

a) bubbling

  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 search public 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 partial refresh technology. In traditional pages, users need to click a button or an event to trigger a request to refresh the page, while asynchronous technology can trigger events without clicking, which enhances the user experience. For example, the asynchronous loading of the shopping cart in the mall, when you click on the product, you do not need to request the background and directly modify the parameters dynamically.

9. The calling sequence 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 constructor

e) Subclass ordinary methods

f) Override the method of the parent class, then print the overridden method

10. Calls of inner and outer classes

a) The inner class can directly call the member variables of the outer class, including private, by using the this. keyword referenced by the outer class.

b) When the outer class calls the inner class, it needs to create the inner class object

11. Multithreading

a) A process is an independent operating 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 multi-threaded program, multi-threaded concurrency can improve the efficiency of the program. The cpu will not enter an idle state because a thread is waiting for resources, it will give the 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 the GC in the JVM virtual

d) The priority level of the thread: each thread has a priority level, and the one with a higher limited level can obtain CPU resources first to make the thread transition from the ready state to the running state. It is also possible to customize the limited level of threads

e) Deadlock: At least two or more threads strive for more than two cpu resources, to avoid deadlock, avoid using nested locks, 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 a framework can reduce the workload and improve work efficiency. It is a layered structure, that is, the corresponding layer handles the corresponding business logic and reduces the coupling of the code. The core of spring is IOC inversion of control and AOP aspect-oriented programming. IOC control inversion mainly emphasizes that the relationship between programs is controlled by the container, the container controls the object, and controls the acquisition of external resources. The reverse is that in traditional programming, we create objects to obtain dependent objects, while in IOC, the container helps us create objects and inject dependent objects. It is the container that helps us find and inject objects, and objects are acquired. , so it is called inversion.

b) AOP: Aspect-oriented programming, mainly to manage the business of the system layer, such as logs, permissions, things, etc. AOP is to split the encapsulated object, find out the common behavior that affects multiple objects, and encapsulate it into a reusable module, this module is named aspect (aspect), the aspect connects those with business logic Unrelated, but is extracted and encapsulated by the logic commonly called by the business modules, which reduces the repetitive 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 the ROM object-relational mapping mechanism. It maps operations between tables to operations between objects and 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 makes the modification of the object correspond to the modification of the data row by mapping the entity class of the data table.

14. The difference between Struts1 and Struts2

15. Optimal deletion of a character in the string

16. The difference between Arraylist and linkedlist

a) All 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 faster, and it can be obtained by subscripting an array, while linkedlist requires Move the pointer. When storing elements and deleting elements, linkedlist is more efficient, just need to move the pointer to the specified position to add or delete, while arraylist needs to move data.

 

17. The difference between mybaties and ibatise

 

18. Database optimization

a) Select the appropriate field, for example, the mailbox field can be set to char (6), try to set the field to notnull, so that the database does not need to compare null values ​​when querying

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

c) Manually create temporary table using union union query

d) Open the transaction, when the database executes multiple statements and there is an error, 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 cannot guarantee the relevance of data, using foreign keys can ensure the relevance of data

f) Using an index, an index is a common method to improve database performance, it can make the database server retrieve specific rows much faster than no index, especially for max, min, order by queries, the effect is more obvious

g) Optimized query statements. In most cases, the use of indexes can improve the speed of the query, but if the SQL statements are not used properly, the indexes cannot exert their characteristics.

 

19. Tomcat server optimization (memory, concurrent connections, cache)

a) Memory optimization: mainly to optimize the Tomcat startup parameters, we can modify its maximum memory and so on in the Tomcat startup script.

b) Optimization of the number of threads: Tomcat's concurrent connection parameters are mainly configured in server.xml in the Tomcat configuration file, such as modifying the minimum number of idle connection threads to improve system processing performance and so on.

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

 

20. HTTP protocol

a) Commonly used request methods are get, post

b) The difference between Get and post: to transmit data, get carries parameters and access addresses to transmit, and users can see it. In this case, the information will be unsafe, resulting in information leakage. The post encapsulates the fields and corresponding values ​​in the entity, which is invisible to the user. Get has restrictions on passing parameters, while post has no restrictions.

 

21. TCP/UDP protocol

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

a) Collection collection interface, List, set implement Collection interface, arraylist, linkedlist, vector implement list interface, stack inherits vector, Map interface, hashtable, hashmap implement map interface

 

23. The process of class loading

a) When encountering a new class, 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 static member variables are allocated to the static area of ​​the method area, the non-static member variables are allocated to the non-static area, and then the static member variables are initialized and assigned default values. After the default values ​​are assigned, they will be written according to the static member variables. The position is assigned the display value, and then the static code is executed. Class loading is complete 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) All static member variables are initialized, the static code block will also be executed, and only executed once when the class is loaded

c) When a New object is created, the jvm will allocate a large enough storage space in the heap

d) The storage space is cleared, default values ​​are assigned to all variables, and all object references are assigned null

e) Give the field some initialization operations according to the writing position

f) call the constructor method (no inheritance)

 

25. JVM optimization

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

b) Choice of Garbage Collector

 

26. High concurrent processing

a) Know a little about high concurrency issues, such as when one 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 lock synchronization Only one person can do it at a time. At this time, the locking mechanism can be used, and 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 not only ensures the readability of the data, but also ensures the exclusivity of the saved data, guarantees the performance and solves the dirty caused by concurrency. Read data problem.

 

27. Understanding of things

a) Things are atomic, consistent, durable, isolated

b) Atomicity: It means that in a thing, either all executions succeed, or all fail rollbacks.

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

d) Persistence: The operation of multiple data of 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 filterdispatcher after some column filtering, and 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, actioninvocation is responsible for finding the corresponding return result according to the configuration of stuts.xml. The returned result is usually a jsp page.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325074009&siteId=291194637