Java Internet interview questions include XX network (Internet finance C round enterprise) interview questions

This interview question is the summary after my interview. I have written everything I can think of. If there is anything wrong, please correct me

XX network interview

question

1. How do oracle and mysql paging work?

2. What is the difference between Oracle's rowID and rowNum;

3. When the amount of Oracle or MySQL data is relatively large, how to divide the paging faster, that is, how to use the rowID keyword to quickly paginate;

4. How to query by paging when the amount of Mysql data is very large (several millions and tens of millions);

5. Where is the order by side used for Oracle and mysql paging;

6. Index: The difference between a single-column index and a joint index; when a joint index is used, there are three word fields of multiple fields (A, B, C). If there is only BC, will this index be used? The order in which the database parses SQL, SQL parser, converted into execution plan

7. The parsing sequence of database SQL, SQL parser, and execution plan;

8. Problems related to database connection pool;

9. Thread pool;

10. Distributed framework: dubbo;

11. Look at the source code more;

12, java synchronization synchronized problem;

13. Collection class: a subset of collection and set list; the difference between arrayList and linkedList; how to turn these two lists into thread-safe lists

14. Common Linux commands: top, kill-9: why add -9?

15. Linux constraints on the number of threads of a user;

16. Oracle aggregate query function;

17. Where is the singleton pattern used?

18. How is the Chain of Responsibility model implemented, and the difference between the strategy model and the Chain of Responsibility model;

19. Have you written a filter?

20. Common annotations of SpringMVC; ulimit, service, controller, responseBody, Transaction

21. How to run again after the scheduled task fails; when sending text messages and emails due to network reasons, there are 100 people and only 30 people are sent. How to realize the method of resending the remaining 70 people after the system restarts;

22. Which layer is the SpringMVC transaction added to (dao layer, service layer, controller layer);

23. (Transaction) transaction annotation;

24. Redis cache;

25. MQ cache system;

 

 

The interviewer's suggestion: there are few design patterns written, there is no problem, but you need to pay attention to the basic knowledge of Java;

 

 

 

 

 

Answer

1. For the Mysql database, we can use the limit statement for paging, and for the oracle database, we can use the rownum method for paging;

Mysql's limit m,n statement;

Among the two parameters after Limit, the parameter m is the starting table, which starts from 0; the parameter n is the number of records returned. If we need pagination, we can put these two values ​​at the top;

rownum' of Oracle database;

In the oracle database, the paging method is not as simple as Mysql, it needs to rely on rownum to achieve. RowNum represents the row number of a record, the row number is the data loaded into the memory and then taken out. He assigns a row number to each row after getting it, so it is impossible to get the paging data by setting the rownum range at the top of the query statement.

Select * from

(

     Selecta.* ,a.rownum rn from a

     (

    (Select * from user ) a where a.rownum<20

) where rn>10;

)

The innermost query select * fromuser represents the original query statement without page turning.

Rownum<20 and rn>10 control the range of each page of the paging query; the share query condition given above has higher efficiency in most cases. The purpose of paging is to control the size of the output result set and return the result set as soon as possible. In the above query statement, this consideration is mainly reflected in the sentence where a.rownum < 20 , and there is another query method as follows:

Select * from

(

Select A.*,rownum rn from

     Select* from user a

)where rn between 10 and 20

)

In most cases, the first method is more efficient. The reason for the high efficiency is related to the parsing order of SQL. Interested students can Baidu by themselves.

2. What is the difference between Rowed and rownum

Rownum and rowid are virtual columns , but the meaning is completely different. Rowid is the physical address, which is used to locate the physical storage location of specific data in oracle, and rownum is the sorting of sql output results. In layman's terms: rowid is unchanged, rownum will change, especially when using order by;

Rowed: The position used to locate a certain piece of data in the data table is unique and unchanged.

Rownum: Indicates the position of a record in the entire result set. The same record has different query conditions, and the rowid will not change.

3. When the data volume of Oracle and MySQL is relatively large, how to optimize SQL so that the query speed is faster when paging;

4. When Oracle and MySQL use paging, where is the orderby placed?

Oracle uses orderby when paging, which is placed in two levels of nesting, that is, in two where clauses: where rownum<30 and whererownum>10.

5. The difference between single-column index and joint index, how to use joint index;

Single-column index: As long as the index column appears in the condition (where clause), no matter where it is, the index query can be used;

Joint index: 1) If the first column or all of the joint index appears in the conditional query, the joint index can be used (related to the SQL parsing order); 2) As long as the conditions are connected together in the condition, no matter before or after, the above will be used. Joint index; 3) If the first column of the joint index does not appear in the query condition, but the second column or the third column of the joint index appears, the joint index is not used for the query.

When do you need to build an index: Generally speaking, the columns appearing in where and jion need to be indexed, but this is not entirely the case, because mysql is only for <,<=,=,>,>=,BETWEEN,IN , and some science subjects will use indexes; mysql will not use indexes when querying with wildcards % and _.

Disadvantages of index: Although the index greatly improves the query speed, colleagues will reduce the speed of updating the table, such as insert, update, and delete the table; because when updating the table, mysql not only saves the data, but also saves the index file.

If the amount of data is large and the index is used at the same time, then if a large amount of data needs to be added at this time, the index can be deleted in the early morning, and then the data can be added. After the data is added, the joint index can be added.

6. SQL parsing order, SQL parser - this part is Baidu

7. Database connection pool:

The database connection pool is responsible for allocating, managing and releasing database connections. It allows the application to reuse an existing database connection instead of re-establishing one. Releasing a database whose idle time exceeds the maximum idle time should be avoided because the database connection is not released. This technology can significantly improve the performance of database operations;

Principle: The basic idea of ​​connection pooling is that when the system is initialized, the database connection is stored as an object in the memory. When the user needs to access the database, instead of establishing a new connection, an already established idle connection is taken from the connection pool. connection object. After using it, the user does not close the connection, but puts the connection back into the connection pool for the next request. The establishment and disconnection of connections are managed by the connection pool itself. Colleagues can also control the initial number of connections in the connection pool, the upper and lower limits of the connection, the maximum number of times each connection is used, the maximum idle time, etc. by setting the parameters of the connection pool;

There are several open source database connection pools in Java: DBCP, Proxool, C3P0

C3P0 is less efficient than small resources;

There is a bug in DBCP;

Proxool is better, and provides real-time monitoring of connection pool status, which is convenient for discovering connection pool leaks.

The relationship between connection pool, data source, and JNDI:

connection pool:

The connection pool is provided by the container (such as tomcat) to manage the connection objects in the connection pool;

The connection pool automatically allocates connection objects and recycles idle connections;

Connection objects in the connection pool are created by the data source (DataSource).

Connection pool (Connection Pool) is used to manage connection (Connection) objects

data source:

The data source (DataSource) is used to connect to the database and create a connection object;

The Java.sql.DataSource interface is responsible for establishing a connection with the database, which is provided by Tomcat and saves the connection in the connection pool.

JDNI (Java Naming and Directory Interface, Java Naming and Directory Interface):

Use JNDI to get the data source in the program, and put the connection objects created through the data source into the connection pool for management.

 

8. There are many problems in the thread pool, and it is more complicated. I will not explain it here. Please refer to Baidu for details: http://www.importnew.com/12773.html

9. Distributed framework dubbo - Baidu, I have never used it. . .

10. The problem of Javasynchronize is also Baidu, and the answer is all online;

11. Collection class: the difference between ArrayList and linkedList:

ArrayList is fast when querying, and is implemented internally with arrays. The array has subscripts, so the query speed is faster, but it is slower when adding and modifying. LinkedList is faster when adding and modifying, but slower when querying. The internal implementation of linkedList is as follows Chain structure, the elements stored in it are connected at the end, and the next element can be found directly when the previous one is found, so when adding or modifying, the address pointing to the next element can be directly modified, but the query is slow, and the entire list needs to be traversed. Inquire;

Where ArrayList is thread-unsafe, linkedList is thread-safe. How to turn two lists into thread-safe lists:

List<String> list =Collections.synchornizedList(new ArrayList<String>());

List<String> list =Collections.synchornizedList(new LinkedList<String>());

For more details, please see: http://blog.csdn.net/hp_yangpeng/article/details/78510991

12. Common instructions for server maintenance:

Detailed explanation of top command: This command is often used to monitor the system status of Linux, such as cpu and memory usage


first row:

1:08:45: Current system time;

10 days, 3:05 - the system has been running for 10 days, 3 hours and 05 minutes (it has not been restarted during this period);

Load average: The following three parameters need to be calculated, and after the calculation, it can be judged whether it is overloaded;

second line:

Tasks: 135 total, the system now has a total of 135 processes, of which one is running, 134 are sleeping, and 0 zombie processes (zombie: zombie process);

The third line: the status of the CPU (four CPUs in total)

0.3%us - the percentage of CPU occupied by user space;

0.0%sy – the percentage of CPU space occupied by internal medicine;

0.0%ni - The percentage of CPU occupied by processes whose priorities have changed

0.0% wa-IO waits to occupy the CPU percentage

0.0% hi – percentage of CPU occupied by hardware IRQs

0.0% si - the percentage of CPU occupied by software Interrupts;

Fourth line: memory status

3908060k total - total physical memory (4g);

3660048k used – total memory in use (3.6G)

148012k free-total amount of free memory (148M)

359760 buffers – amount of memory to cache (359M)

Kill -9 kills the process: -9 means forcibly stop the process, sometimes only use kill, the process cannot be killed;

    See: http://blog.csdn.net/hp_yangpeng/article/details/78511051

13. Linux constraints on the number of user threads

Check the maximum number of threads supported by the system, which is generally very large, equivalent to the theoretical value;

cat /proc/sys/kernel/pid_max----------32768

cat /proc/sys/kernel/threads –max 4132217

max_user_process #The system limits the maximum number of threads or processes that can run under a certain user, use the command: ulimit –u

ulimit –u -----------1024

Note: To modify the value of max_user_process, you only need to knee /etc/security/limits.conf, but this parameter needs to be modified /etc/security/limits.d/90-nproc.conf

14. Oracle aggregation query function: Commonly used aggregation functions are: sum, avg, min, max, count, etc. Please refer to Baidu for other aggregation functions.

15. Java Design Patterns

Simple interest mode: There are mainly lazy mode, hungry mode,

The specific implementation is as follows:

1. Lazy mode, thread safety:

Public class singleon{

Privatestatic Singleton instance;

Priate Singleton (){}

Public static synchronized SingletongetInstance(){

If(instance==null){

     Instance= new Singleton();

}

Return instance;

}

}

2. Hungry mode, thread safety;

Public class Singleton {

Privatestatic Singleton instance = new Singleton();

Private Singleton(){}

Public static Singleton  getInstance(){

Return instance

}

}

The chain of responsibility model has a lot of content, and it is recommended to watch videos online for learning;

16. There are many cache problems in Redis and MQ. It is recommended to learn slowly by yourself (I will not)

 


Guess you like

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