In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what are the Java framework interview questions". In the daily operation, I believe many people have doubts about the Java framework interview questions. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the questions of "what are the Java framework interview questions?" Next, please follow the editor to study!
Spring
What's the difference between BeanFactory and ApplicationContext?
BeanFactory can be understood as a factory class that contains bean collections. BeanFactory contains a definition of a bean to instantiate the corresponding bean when a client request is received. BeanFactory can also generate relationships between collaboration classes when objects are instantiated. This frees up the configuration of bean itself and the bean client. BeanFactory also includes bean lifecycle control, calling the client's initialization method (initialization methods) and destruction method (destruction methods). On the face of it, application context, like bean factory, has bean definition, bean association setting, and the function of distributing bean according to request. But application context also provides other functions on this basis. Provides a uniform way to read resource files that support internationalized text messages. Bean events that have been registered in the listener
Life cycle of Spring Bean
The life cycle of Spring Bean is simple and easy to understand. When an bean instance is initialized, a series of initialization operations need to be performed to achieve the available state. Similarly, when a bean is not being called, it needs to be destructed and removed from the bean container. Spring bean factory is responsible for managing the lifecycle of the bean created in the spring container. The life cycle of a Bean consists of two sets of call back methods. The callback method called after initialization. Destroys the callback method that was previously called. The Spring framework provides the following four ways to manage bean lifecycle events: InitializingBean and DisposableBean callback interfaces Custom init () method and destroy () method @ PostConstruct and @ PreDestroy annotation methods in Bean configuration files of other Aware interfaces for special behavior
How to implement Spring IOC
The org.springframework.beans package and org.springframework.context package in Spring form the basis of the Spring framework IoC container. The BeanFactory interface provides an advanced configuration mechanism that makes the configuration of any type of object possible. The ApplicationContex interface extends BeanFactory (which is a subinterface), adding other functions to BeanFactory, such as easier integration with AOP with Spring, mechanisms for handling message resource (for internationalization), event propagation, and special configuration of the application layer, such as WebApplicationContext for Web applications. Org.springframework.beans.factory.BeanFactory is a concrete implementation of the Spring IoC container that wraps and manages the various bean mentioned earlier. The BeanFactory interface is the core interface of the Spring IoC container.
Talk about Spring AOP.
Aspect-oriented programming, in our application, we often need to do some things, but these things have nothing to do with the core business, for example, to record the execution time of all update methods, operators and other information, log, through spring's AOP technology, we can complete this requirement without modifying the update code.
Principle of Spring AOP implementation
There are two main ways of dynamic agent in Spring AOP, JDK dynamic agent and CGLIB dynamic agent. The JDK dynamic proxy receives the proxied class through reflection and requires that the proxied class must implement an interface. The core of JDK dynamic agent is the InvocationHandler interface and Proxy class. If the target class does not implement the interface, Spring AOP chooses to use CGLIB to dynamically proxy the target class. CGLIB (Code Generation Library), a code-generated class library, can dynamically generate subclasses of a class at run time. Note that CGLIB is a dynamic proxy done by inheritance, so if a class is marked as final, it cannot use CGLIB as a dynamic proxy.
Dynamic agents (cglib and JDK)
The JDK dynamic proxy class and delegate class both need to implement the same interface. That is, only classes that implement an interface can use the Java dynamic proxy mechanism. However, in fact, not all classes encountered in use will give you an interface. Therefore, this mechanism cannot be used for classes that do not implement the interface. On the other hand, CGLIB can realize the dynamic proxy to the class.
Spring transaction implementation
1. Coding method the so-called programmatic transaction refers to the implementation of the transaction by coding, that is, similar to JDBC programming to achieve transaction management. 2. Declarative transaction management there are two ways to implement declarative transaction management: based on xml configuration file, and another real business method is annotated with @ Transaction to apply transaction rules to business logic.
The underlying principles of Spring transactions
A, divide the processing unit-IOC because the problem solved by spring is to deal with the local transaction of a single database, the prime minister divides the transaction processing unit with IOC in spring. And put the various configurations of the transaction into the ioc container (setting the transaction manager, setting the propagation characteristics and isolation mechanism of the transaction). B. AOP intercepts the Spring-like transaction module that needs transaction processing. The Spring transaction module realizes declarative transaction processing through the AOP function, the concrete operation (such as the configuration and reading of the transaction implementation, the abstraction of the transaction object), uses the TransactionProxyFactoryBean interface to use the AOP function, generates the proxy proxy object, completes the interception of the proxy method through TransactionInterceptor, and weaves the transaction processing function into the interception method. Read the ioc container transaction configuration properties, convert them into internal data structures (TransactionAttributeSourceAdvisor) required by spring transactions, and convert them into data objects represented by TransactionAttribute. C, the transaction processing implementation (transaction generation, commit, rollback, suspension) spring delegated to the specific transaction processor implementation. Implements an abstraction and adaptation. Suitable specific transaction processors: DataSource data source support, hibernate data source transaction support, JDO data source transaction support, JPA, JTA data source transaction support. These supports are through the design of PlatformTransactionManager, AbstractPlatforTransaction, a series of transaction support. Provides a series of TransactionManager for common data source support. D. Realize the TransactionInterception interface with PlatformTransactionManager and combine it with TransactionProxyFactoryBean to form a design system of Spring declarative transaction processing.
How to customize annotations to implement functions
Creating a custom annotation is similar to creating an interface, but the annotated interface keyword needs to start with the @ symbol. Annotation methods cannot take parameters; the return value types of annotation methods are limited to primitive types, String, Enums, Annotation or arrays of these types; annotation methods can have default values; annotations themselves can contain meta-annotations, which are used to annotate other annotations. Excerpt from: http://www.importnew.com/20286.html
Spring MVC running process
1.spring mvc submits all requests to DispatcherServlet, and it delegates other modules of the application system to do the real processing of the requests. 2.DispatcherServlet queries one or more HandlerMapping to find the Controller that processes the request. After the 3.DispatcherServlet request is submitted to the target Controller 4.Controller for business logic processing, a ModelAndView 5.Dispathcher query will be returned to one or more ViewResolver view parsers to find the view object 6. 0 specified by the ModelAndView object. The view object is responsible for rendering and returning to the client.
Spring MVC startup process
Load-on-startup is configured for the Servlet of Spring MVC in the web.xml file, so when the program starts, the Spring MVC is initialized, the contextConfigLocation property of the configuration is set to Servlet in HttpServletBean, and then WebApplicationContext is created in FrameworkServlet. DispatcherServlet initializes the total components of Spring MVC according to the xml file under the classpath of contextConfigLocation configuration.
The principle of singleton implementation of Spring
Spring implements the creation of Bean instances in a singleton registry, which is cached as a ConcurrentHashMap object.
What design patterns are used in the Spring framework
Proxy mode-is used more frequently in AOP and remoting. Singleton mode-the bean defined in the spring configuration file defaults to singleton mode. Template method-used to solve the problem of code duplication. such as。 RestTemplate, JmsTemplate, JpaTemplate . The front-end controller-Spring provides DispatcherServlet to distribute requests. View help (View Helper)-Spring provides a series of JSP tags and efficient macros to help integrate scattered code into the view. Dependency injection-the core idea that runs through the BeanFactory / ApplicationContext interface. Factory mode-BeanFactory is used to create an instance of an object.
Spring other products (Srping Boot, Spring Cloud, Spring Secuirity, Spring Data, Spring AMQP, etc.)
Netty
Why choose Netty?
API is easy to use and has low development threshold.
Powerful, preset a variety of codec functions, support a variety of mainstream protocols
The customization ability is strong, and the communication framework can be flexibly extended through ChannelHandler
High performance. Compared with other mainstream NIO frameworks in the industry, Netty has the best overall performance.
Mature and stable, Netty fixes all the discovered JDK NIO BUG, and business developers no longer need to worry about NIO's BUG
The community is active, the iteration cycle of the version is short, and the BUG found can be repaired in time. At the same time, more new features will be added.
After a large-scale commercial application test, the quality has been verified. It has been successfully used in many industries, such as Internet, big data, online games, enterprise applications, telecommunications software and so on, which proves that it can fully meet the business applications of different industries. Because of these advantages, Netty has gradually become the preferred framework for Java NIO programming.
Talk about the usage scenario of Netty in the business.
Build various Java middleware with high performance and low latency, such as MQ, distributed service framework, ESB message bus, etc. Netty is mainly used as the basic communication framework to provide high-performance and low-latency communication services; the basic communication framework of public or private protocol stack, for example, asynchronous, high-performance WebSocket protocol stack can be built based on Netty Applications in various fields, such as big data, games, etc., Netty is used as a high-performance communication framework for data distribution, transmission and collection of internal modules to achieve high-performance communication between modules.
Native NIO has epoll bug in JDK version 1.7
It causes Selector empty polling, which eventually results in CPU 100%. Officials claim to have fixed the problem with update18 in JDK version 1.6, but the problem persisted until JDK version 1.7, except that the probability of the BUG was reduced and it was not fundamentally resolved.
What is TCP sticky package / unpacking
1. If the data to be sent is larger than the remaining space in the TCP send buffer, unpacking will occur. 2. The data to be sent is larger than MSS (maximum message length), and TCP will unpack the packet before transmission. 3. The data to be sent is less than the size of the TCP send buffer. If TCP sends out the data written to the buffer many times at once, sticking will occur. 4. If the application layer of the receiving data side fails to read the data in the receiving buffer in time, packet sticking will occur. The solution of TCP sticking / unpacking
1. The sender adds a packet header to each packet, and the header should include at least the length of the packet, so that after receiving the data, the receiver knows the actual length of each packet by reading the length field of the header. 2. The sender encapsulates each packet as a fixed length (if it is not enough, it can be filled with zero padding), so that the receiver naturally splits each packet every time it reads fixed-length data from the receiving buffer. 3. A boundary can be set between packets, such as adding special symbols, so that the receiver can split different packets through this boundary.
Netty thread model
First, Netty uses EventLoop to handle read and write events on a connection, and all requests on a connection are guaranteed to be processed in an EventLoop, and there is only one Thread in an EventLoop, so it is implemented that all events on a connection will be executed in only one thread. An EventLoopGroup contains multiple EventLoop. You can think of an EventLoop as a thread in the Reactor threading model, while an EventLoopGroup is similar to an ExecutorService.
Talk about zero copy of Netty
"Zero copy" means that during computer operation, CPU does not need to consume resources for copying data between memory. It usually refers to the way that when a computer sends a file on the network, it does not need to copy the contents of the file to the user space (User Space) but directly transmits it to the network in the kernel space (Kernel Space).
Netty internal execution process
The receiving and sending ByteBuffer of Netty adopts DIRECT BUFFERS, and the direct memory outside the heap is used for Socket reading and writing, and the second copy of byte buffer is not needed. If traditional heap memory (HEAP BUFFERS) is used for Socket read and write, JVM copies the heap memory Buffer into direct memory before writing to Socket. Compared with out-of-heap direct memory, the message has one more memory copy of the buffer during the sending process.
Netty provides composite Buffer objects, which can aggregate multiple ByteBuffer objects. Users can operate the combined Buffer as easily as operating a Buffer, avoiding the traditional way of merging several small Buffer into a large Buffer through memory copy.
The file transfer of Netty adopts the transferTo method, which can send the data of the file buffer directly to the target Channel, which avoids the memory copy problem caused by the traditional circular write. Netty reconnection implementation
1. Heartbeat mechanism to detect connection survival 2. Connection retry at startup 3. Retry when the connection is disconnected while running
At this point, the study of "what are the interview questions for the Java framework" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.