Java interview record review (continuously updated)

day12.30 Guazi used car supply chain (one side)

  1. Self introduction
  2. asked three items
  3. Communication between operating systems
  1. Pipeline communication: Pipeline is a half-duplex communication method, data can only flow in one direction, and can only be used between processes with affinity. Affinities with processes are usually relationships between parent and child processes.
    2. Named pipe FIFO: Named pipe is also a half-duplex communication method, but it allows communication between unrelated processes.
    3. Message queue MessageQueue: The message queue is a linked list of messages, stored in the kernel and identified by the message queue identifier. Message Queuing overcomes the shortcomings of low signal transmission, pipelines that can only carry unformatted character streams, and limited buffer size.
    4. Shared storage ShareMemeory: Shared storage is to map a piece of memory that can be accessed by other processes. This shared memory is created by one process, but can be accessed by multiple processes. Shared memory is the fastest IPC method, and it is specially designed for the inefficiency of other inter-process communication methods. It is often used in conjunction with other communication mechanisms, such as semaphores, to achieve synchronization and communication between processes.
    5. Semaphore Semaphore: A semaphore is a counter that can be used to control access to shared resources by multiple processes. It is often used as a locking mechanism to prevent other processes from accessing a shared resource while a process is accessing the resource. Therefore, it is mainly used as a synchronization method between processes and between different threads in the same process.
    6. Socket: Socket is also an inter-process communication mechanism. Unlike other communication mechanisms, it can be used for different and inter-process communication.
    7. Signal (sinal): A signal is a relatively complex communication method used to notify the receiving process that a certain time has occurred.
  1. How is the database index implemented?

What is an index: An index is a data structure that helps MySQL efficiently obtain data. Extracting the backbone of the sentence, you can get the essence of the index: the index is a data structure. Database systems also maintain data structures that satisfy specific lookup algorithms, and these data structures reference data in such a way that advanced lookup algorithms can be implemented on these data structures. This data structure is an index.
The index of the database is actually to make the query data efficient. Indexes can greatly improve the retrieval speed of MySQL.

  • At present, most databases and their file systems use B-Tree or its variant B+Tree as the index structure.

  • Implementation of indexes in MySQL:
    In MySQL, indexes belong to the concept of storage engine level. Different storage engines implement indexes in different ways. This article mainly discusses the index implementation methods of MyISAM and InnoDB .

  • MyISAM index implementation : The MyISAM engine uses B+Tree as the index structure, and the data field of the leaf node stores the address of the data record. The following figure is the schematic diagram of the MyISAM index:
    insert image description hereThe index method of MyISAM is also called "non-clustered", which is called to distinguish it from the clustered index of InnoDB.

  • InnoDB index implementation:
    Although InnoDB also uses B+Tree as the index structure, the specific implementation is completely different from MyISAM.

The first major difference is that InnoDB's data files are themselves index files. From the above, it is known that the MyISAM index file and the data file are separated, and the index file only saves the address of the data record. In InnoDB, the table data file itself is an index structure organized by B+Tree, and the data field of the leaf node of this tree saves complete data records. The key of this index is the primary key of the data table, so the InnoDB table data file itself is the primary index.
insert image description here
As shown in the figure, the leaf nodes contain complete data records. Such an index is called a clustered index. Because the data files of InnoDB are aggregated by the primary key, InnoDB requires that the table must have a primary key (MyISAM may not have it). If it is not specified explicitly, the MySQL system will automatically select a column that can uniquely identify the data record as the primary key. If it does not exist For this type of column, MySQL automatically generates an implicit field as the primary key for the InnoDB table. The length of this field is 6 bytes and the type is long.
For more details, see this article https://blog.codinglabs.org/articles/theory-of-mysql-index.html
5. The difference between clustered index and non-clustered index is the
same: both are B+ trees data structure

  • Clustered index: The data storage and index are put together, and they are organized in a certain order. When the index is found, the data is found. The physical storage order of the data is consistent with the index order, that is, as long as the indexes are adjacent , then the corresponding data must also be placed adjacently on the disk.
  • Non-clustered index: The leaf node does not store data, but stores the address of the data row, that is to say, find the position of the data row according to the index and then go to the disk to find the data, which is somewhat similar to the directory of a book, for example, to find the first The first section of the third chapter, then look in the directory, find the corresponding page number, and then go to the corresponding page number to read the article.
  1. How to ensure synchronization between threads in Java

1.synchronized keyword, modified method, to ensure that this method will only have one object access. Modified code blocks. The statement block modified by this keyword will be automatically added with built-in lock to achieve synchronization.
1.synchronized keyword, modified method, to ensure that this method will only have one object access. Modified code blocks. The statement block modified by this keyword will be automatically added with built-in lock to achieve synchronization.
2.wait() and notify
wait(): Make an object in a waiting state and release the lock of the held object.
sleep(): Makes a running thread sleep. It is a static method. Call this method to catch InterruptedException.
notify(): Wake up a thread in a waiting state. Note that when this method is called, it cannot exactly wake up a thread in a waiting state, but the JVM determines which thread to wake up, and not by priority.
ALLnotify(): Wake up all the threads that are in the waiting state. Note that it is not to give all the awakened threads an object lock, but to let them compete.
3. Use special domain variables (volatile) to achieve thread synchronization 1. The volatile
keyword provides a lock-free mechanism for accessing domain variables
2. Using volatile to modify a domain is equivalent to telling the virtual machine that the domain may be updated by other threads.
3. Therefore, each time the field is used, it is recalculated instead of using the value in the register.
4.volatile does not provide any atomic operations, nor can it be used to modify variables of final type.
5. How to use: Just add the volatile keyword before the mutex variable.

  1. What is AOP
  • AOP (Aspect-OrientedProgramming, aspect-oriented programming) can be said to be the supplement and improvement of OOP (Object-Oriented Programming, object-oriented programming).

It is oriented to a cross-cutting technology, dissects the inside of the encapsulated object, and encapsulates the publicity that affects multiple classes into a reusable module, which is named "Aspect", that is, aspect. Simply put, it is to encapsulate the logic or responsibilities that are not related to the business, but are commonly called by the business modules, which is convenient for reducing the repetitive code of the system, reducing the coupling between modules, and is conducive to future operability and maintainability sex. AOP represents a horizontal relationship. If the "object" is a hollow cylinder, which encapsulates the properties and behavior of the object; then the aspect-oriented programming method is like a sharp blade, cutting these hollow cylinders on to get its internal message. The cut section is the so-called "face". Then it restored these cut-away sections with its ingenious hands, leaving no traces.

  1. DI
    DI (Dependency Injection) Dependency Injection
    DI-Dependency Injection, that is, "dependency injection": the dependencies between components are determined by the container at runtime. To put it figuratively, the container dynamically injects a dependency into the component . The purpose of dependency injection is not to bring more functions to the software system, but to increase the frequency of component reuse and build a flexible and extensible platform for the system. Through the dependency injection mechanism, we only need to specify the resources required by the target through simple configuration without any code, and complete our own business logic, without caring where the specific resources come from and who implements them.
    Benefits: Decoupling between modules is achieved.

  2. IOC
    IOC (Ioc-Inversion of Control, that is, "inversion of control", is not a technology, but a design idea.) The
    object is created by the original program itself and becomes the program receiving object.
    Programmers mainly focus on business implementation.
    The decoupling of service and dao is realized, and the service layer and dao layer are separated. There are no direct dependencies.
    If the implementation of dao changes, the application itself does not need to change.

What is controlled: Who controls the creation of objects: The creation of traditional application objects is controlled by the program itself. After using spring, it is created by spring.
Reverse: Forward rotation means that the program creates objects, and reverse rotation means that the program itself does not create objects, but becomes passively received objects.
Summary: In the past, objects were created by the program itself. After using spring, the program passively receives objects created by spring.

Ioc – is a programming idea. Changed from active programming to passive reception;
the realization of Ioc is realized through the ioc container. Ioc container – BeanFactory

  1. Proxy mode (dynamic proxy or static proxy)
    Proxy mode (Proxy) provides a proxy for other objects to control access to this object.
    Thought: The function that the main body wants to realize needs a proxy class to realize it for me. Implementation method: Implement the same interface
    For example: Xiaobai wants to pursue Xiaohong, and the pursuit methods include sending flowers and sending roses. But Xiao Bai was too shy to take the initiative, so he asked Xiao Huang to chase after him. So let Xiao Huang send flowers and roses for him. Therefore, the methods to be implemented by the proxy class and the main body are the same.
  2. Factory pattern
    Simple factory pattern: implement a base class, then encapsulate each operation into a concrete class and inherit from this class. In this way, each time you add a method in the future, you only need to add a new class.
    Factory method pattern: In the factory method pattern, the factory parent class is responsible for defining the public interface for creating product objects, while the factory subclass is responsible for generating specific product objects. The purpose of this is to delay the instantiation of the product class to the factory child. It is done in the class, that is, through the factory subclass to determine which specific product class should be instantiated.
    The abstract factory pattern creates a family of objects, that is, many objects instead of one object, and these objects are related, that is, they must be created together. The factory method pattern is only used to create an object, which is very different from the abstract factory pattern.
  3. what is dirty read
  4. affairs
  5. SQL statement
  6. reverse linked list
LinkList reverseLink(LinkList head)
{
    
    
	

	LinkList newhead=(LNode*)malloc(sizeof(LNode));
	newhead->next=NULL;
	newhead=newhead->next;
	LinkList node;
	while(head!=NULL)
	{
    
    
		node=head;
		head=head->next;
		node->next=newhead;
		newhead=node; 
	}
	return newhead;
}

day 1.4 (Jingwei Hengrun internship)

  1. Several ways to create objects in Java

    1. Use the new keywordEmployee emp1 = new Employee();
    2. Use the newInstance method of the Class classEmployee emp2 = (Employee) Class.forName("org.programming.mitra.exercises.Employee").newInstance();
    3. Use the newInstance method of the Constructor classConstructor<Employee> constructor = Employee.class.getConstructor(); Employee emp3 = constructor.newInstance();
    4. Use the clone methodEmployee emp4 = (Employee) emp3.clone();
    5. use deserializationObjectInputStream in = new ObjectInputStream(new FileInputStream("data.obj")); Employee emp5 = (Employee) in.readObject();
  2. Do you know about reflection?
    Reflection is to map various components in a Java class into Java objects one by one.

Portal: https://blog.csdn.net/sinat_38259539/article/details/71799078?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog -BlogCommendFromMachineLearnPai2-1.channel_param
3. What is the difference between final and finally
final:

  • A final modified class cannot be inherited because it is a final class;
  • A final-modified variable is a constant that can only be assigned once;
  • Final modified methods cannot be overridden, but can be overloaded;
  • final can modify classes, methods, and variables;
  • Inner classes can only access local variables modified by final.
    finally:
  • The finally block is usually placed after try and catch. Sometimes it can be placed directly after try, but sometimes it cannot be placed.
  • The statement in finally is a statement that must be executed after normal execution or exception handling. The finally block is generally used to close (release) physical resources (database connections, network connections, disk files, etc.). The resource must be closed whether or not an exception occurs.
  • When no necessary resources need to be released, the finally block can not be defined.
  • The code in the finally block can always be executed, which means that no matter what code is executed in the try and catch blocks, whether an exception occurs or normal operation, the finally block will definitely be executed. The method to exit the virtual machine is called in the catch block, otherwise the finally block will be executed anyway, as shown in the following figure:
  1. The difference between HashMap and hashtable
    HashMap is not thread-safe: HashMap is a subclass of the map interface and is an object that maps keys to values, where both keys and values ​​are objects and cannot contain duplicate keys, but can contain duplicate values. HashMap allows null key and null value while hashtable does not.
    HashTable: HashTable is thread-safe, HashMap is a lightweight implementation of Hashtable (non-thread-safe implementation), they all complete the Map interface, the main difference is that HashMap allows null (null) key values ​​(key), due to non-thread-safety , which may be more efficient than Hashtable. Hashtable does not allow null keys and values.
    insert image description here

  2. Override and Overload
    Override: Override is to rewrite the implementation process of the method that is allowed to be accessed by the subclass, and neither the return value nor the formal parameters can be changed. That is, the shell remains unchanged, and the core is rewritten!
    When you need to call the overridden method of the superclass in the subclass, use the super keyword.
    Overloading: Overloading is in a class with the same method name but different parameters. The return types can be the same or different.

day1.5 Beijing Oriental Guoxin (one side) (offered)

  1. Design Pattern:
    Singleton Pattern:
  2. The difference between #{} and ${} in mybatis
  3. Graph traversal methods
    Depth-first search, breadth-first search
  4. How to traverse a binary tree
  5. The way to create a thread
    Inherit the thread class, implement the runnable interface, and create a thread through Callable and Future
  6. Three ways of dependency injection
    Constructor injection, setter injection, annotation injection.
  7. left join right join inner join

day1.6 Long Ying (offered)

1. tcp three-way handshake

2. 1*0.3 The multiplication of both types is 0.3

  1. The three normal forms of database design
    First normal form (to ensure that each column remains atomic)
    Second normal form (to ensure that each column in the table is related to the primary key)
    Third normal form (but each column of the table is directly related to the primary key column, not indirectly related. )

Guess you like

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