Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the interview questions of Java basic framework?

2025-01-18 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 basic framework interview questions". In the daily operation, I believe that many people have doubts about the Java basic 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 basic framework interview questions?" Next, please follow the editor to study!

81. What are the benefits of using the Spring framework?

Lightweight: Spring is lightweight, and the basic version is about 2MB.

Control inversion: Spring achieves loose coupling through control inversion, and objects give their dependencies instead of creating or finding dependent objects.

Aspect-oriented programming (AOP): Spring supports aspect-oriented programming and separates application business logic from system services.

Containers: Spring contains and manages the lifecycle and configuration of objects in the application.

MVC framework: Spring's WEB framework is a well-designed framework and a good alternative to the Web framework.

Transaction management: Spring provides a continuous transaction management interface that can be extended from local transactions down to global transactions (JTA).

Exception handling: Spring provides convenient API to convert specific technology-related exceptions (such as those thrown by JDBC,Hibernate or JDO) into consistent unchecked exceptions.

eighty-two。 What is the usual implementation of ApplicationContext?

FileSystemXmlApplicationContext: this container loads the definition of beans from a XML file, and the full path name of the XML Bean configuration file must be provided to its constructor.

ClassPathXmlApplicationContext: this container also loads the definition of beans from a XML file. Here, you need to set classpath correctly because this container will look for bean configuration in classpath.

WebXmlApplicationContext: this container loads a XML file that defines all the bean of a WEB application.

83, what is dependency injection for Spring? What are the methods for dependency injection

Dependency injection, an aspect of IOC, is a common concept with many interpretations. The concept means that you don't have to create an object, you just need to describe how it is created. You do not assemble your components and services directly in the code, but describe which components need which services in the configuration file, and then a container (IOC container) is responsible for assembling them.

Constructor dependency injection: constructor dependency injection is achieved by a container triggering the constructor of a class that has a series of parameters, each representing a dependency on other classes.

Setter method injection: Setter method injection is that the container instantiates the bean by calling the no-parameter constructor or no-parameter static factory method, and then calls the setter method of the bean, that is, the setter-based dependency injection is realized.

84, what is Spring beans?

Spring beans are the java objects that form the backbone of Spring applications. They are initialized, assembled, and managed by Spring IOC containers. These beans are created from the metadata configured in the container. For example, it is defined in the form in the XML file.

The beans defined by the Spring framework is a single beans. There is a property "singleton" in bean tag, which is a singleton if it is assigned a TRUE,bean, otherwise it is a prototype bean. The default is TRUE, so all beans in the Spring framework are singleton by default.

85, explain the scope of several bean supported by Spring.

The Spring framework supports the following five bean scopes:

Singleton: bean has only one instance in each Spring ioc container.

Prototype: a definition of bean can have multiple instances.

Request: a bean is created for each http request, and this scope is valid only in the web-based Spring ApplicationContext case.

Session: in a HTTP Session, a bean definition corresponds to an instance. This scope is valid only in web-based Spring ApplicationContext cases.

Global-session: in a global HTTP Session, a bean definition corresponds to an instance. This scope is valid only in web-based Spring ApplicationContext cases.

The default Spring bean scope is Singleton.

86, explain the life cycle of bean in the Spring framework.

The Spring container reads the definition of bean from the XML file and instantiates the bean.

Spring populates all the attributes according to the definition of bean.

3. If bean implements the BeanNameAware interface, Spring passes the ID of bean to the setBeanName method.

4. If Bean implements the BeanFactoryAware interface, Spring passes beanfactory to the setBeanFactory method.

5. If there are any BeanPostProcessors,Spring associated with bean, they will be called within the postProcesserBeforeInitialization () method.

6. If bean implements IntializingBean, call its afterPropertySet method, and if bean declares the initialization method, call this initialization method.

7. If there is a BeanPostProcessors and bean association, the postProcessAfterInitialization () method of these bean will be called.

8, if bean implements DisposableBean, it will call the destroy () method.

87, how to inject a java collection in Spring?

Spring provides configuration elements for the following collections:

Type is used to inject a list of values, allowing the same value.

Type is used to inject a set of values and the same values are not allowed.

Type is used to inject a set of key-value pairs, both of which can be of any type.

Type is used to inject a set of key-value pairs, and both keys and values can only be of type String.

88, explain different ways of automatic assembly.

There are five ways of auto-assembly to guide Spring containers to do dependency injection in the auto-assembly mode.

No: the default is not to auto-assemble, but to assemble by explicitly setting the ref property.

ByName: by automatically assembling the parameter name, the Spring container finds that the autowire property of the bean is set to byname in the configuration file, and then the container attempts to match and assemble a bean with the same name as the property of the bean.

ByType:: is automatically assembled by parameter type, and the Spring container finds that the autowire property of bean is set to byType in the configuration file, and then the container attempts to match, assemble and have the same type of bean as the property of the bean. If more than one bean meets the criteria, an error is thrown.

Constructor: this approach is similar to byType, but to provide constructor parameters, if there is no definite constructor parameter type, an exception will be thrown.

Autodetect: first try to use constructor for automatic assembly, and if it doesn't work, use byType.

What are the advantages of transaction management in the 89J Spring framework?

It provides an immutable programming mode for different transaction API such as JTA,JDBC,Hibernate,JPA and JDO.

It provides a set of simple API for programmatic transaction management rather than some complex transaction API such as

It supports declarative transaction management.

It integrates well with Spring's various data access abstraction layers.

ninety。 What is Java-based Spring annotation configuration? Give some examples of annotations.

Java-based configuration allows you to do most of your Spring configuration with the help of a small amount of Java annotations rather than through XML files.

Take the @ Configuration annotation as an example, which marks that the class can be used as a definition of bean and used by the Spring IOC container. Another example is the @ Bean annotation, which indicates that this method is going to return an object to register in the Spring application context as a bean.

At this point, the study of "what are the interview questions for the Java basic 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report