Java high-frequency interview questions and answers collation (will continue to be updated)

Disclaimer: Just record your own study notes, if there is something wrong, please help us to bring it up

One: Java basics

1. Does Java support multiple inheritance?

  • Classes in Java do not support multiple inheritance, only single inheritance, that is, a class has only one parent class. But the interface in Java supports multiple inheritance, that is, a sub-interface can have multiple parent interfaces. The function of the interface is to expand the function of the object. A sub-interface inherits multiple parent interfaces, indicating that the sub-interface has expanded multiple functions. When the class expands the interface, the class expands the corresponding function.

2.

Two: Operating System Basics

1. What is the difference between process and thread?

  • A process is an application program that is executing. A process is a running activity on a certain data set of a program with a certain independent function. A process is an independent unit of the system for resource allocation and scheduling. A thread is an execution sequence within a process. A process can have multiple threads, and a thread is also called a lightweight process.

Three: database foundation

1. What happens without considering the isolation of the database?

  1. Dirty read:
    Dirty read refers to a transaction that reads the data of another uncommitted transaction in the process of processing data.
    example:
--原数据
--id    name
--1     lisi
 
--事务1
START TRANSACTION
updata t_table set name = 'wangwu' where id = 1;    --此时事务2查询id = 1
ROLLBACK
 
--事务2
select * from t_table where id = 1;        --查询到 id = 1, name = 'wangwu'

Transaction 1 is not committed, and the name is still lisi, but transaction 2 reads name = wangwu, which is a dirty read.
2. Non-repeatable read:
Non-repeatable read refers to a certain data in the database,Within a transactionThe multiple queries returned different results because the data was modified and submitted by another transaction during the query process.

--原数据
--id    name
--1     lisi
 
--事务1
select * from t_table where id = 1;    -- 查询到 id = 1, name = list, 事务2在此时提交
select * from t_table where id = 1;    -- 查询到 id = 1, name = wangwu
 
--事务2
start transaction;
update t_table set name = 'wangwu' where id = 1;
COMMIT;
 

The difference between non-repeatable read and dirty read is that dirty read reads an uncommitted data, while non-repeatable read reads the data submitted by the previous transaction.
3. Phantom reading:
Phantom reading is a phenomenon that occurs when a transaction is not independently executed. For example, transaction T1 modifies a data item of all rows in a table from "1" to "2". At this time, transaction T2 inserts a row of data items into the table, and the value of this data item It is still "1" and submitted to the database. If the user operating transaction T1 checks the newly modified data again, he will find that there is still a row that has not been modified. In fact, this row is added from transaction T2, which seems to have an illusion. This is a phantom reading.

Both phantom reads and non-repeatable reads read another committed transaction (this is different from dirty reads), the difference is that non-repeatable read queries are all the same data item, while phantom reads are for a batch The data as a whole (such as the number of data).

2. The isolation level of the database?

  • Read Uncommitted:
    In this isolation level, all transactions can see the execution results of other uncommitted transactions. Read uncommitted data (dirty read).
  • Read Committed:
    This is the default isolation level for most database systems (but not the default for MySQL). It satisfies the simple definition of isolation: a transaction can only see the changes made by the committed transaction.
  • Repeatable Read:
    This is MySQL's default transaction isolation level, which ensures that multiple instances of the same transaction will see the same data row when reading data concurrently.
  • Serializable (Serializable):
    This is the highest isolation level, which solves the problem of phantom reading by forcing transaction ordering to make it impossible to conflict with each other.
    In MySQL, these four isolation levels are implemented, and the possible problems are shown in the following figure:
    Insert picture description here

Guess you like

Origin blog.csdn.net/qq_44867340/article/details/112879620