Java programmers how to respond to interview questions which face Spring

  Java programmers how to respond to the interview? Spring face questions What? Spring is a lightweight container IOC and AOP framework is to provide basic services for a Java application framework that aims to simplify the development of enterprise applications. With the wide application in the enterprise of the Spring Framework, Java programmers in the interview process is also often a question of mastery of Spring. The following is thousands Spring front surface finishing small series of questions to resolve, hoping to bring help to everyone.

0aVQCPXRdbM

  Spring's advantage?

  1) spring design is a low-invasive, low pollution code;

  2) spring mechanism of DI dependencies between objects referred frame processing to reduce coupling assembly;

  3) Spring AOP provides technology to support the centralized management of some common tasks, such as security, transactions, logs, rights, etc., in order to provide better reuse;

  4) spring for mainstream application framework provides integrated support.

  What IOC that?

  IOC (Inversion Of Controll, Inversion of Control) is a design concept, originally created objects in the program manual control, handed over to the Spring framework to manage. Spring is used to achieve IOC IOC container carrier, IOC container is actually a Map (key, value), Map is stored in various objects.

  This can greatly simplify application development, application freed from the complex dependencies. IOC container like a factory, if you need to create an object only needs to configure the configuration file / annotation can be, regardless of how objects are created out, greatly increasing the maintainability of the project and reduce the development effort.

  What AOP is?

  AOP (Aspect-Oriented Programming, aspect-oriented programming) can be those regardless of the business, but is a logical or a liability (such as transaction processing, log management, access control, etc.) service module jointly called packaged to facilitate reducing system code duplication , to reduce the coupling between modules, and facilitates future scalability and maintainability. After using AOP we can put some common functions abstracted, use can be used directly where it is needed, which can greatly simplify the amount of code and improve the scalability of the system.

  Spring AOP是基于动态代理的,如果要代理的对象实现了某个接口,那么Spring AOP就会使用JDK动态代理去创建代理对象;而对于没有实现接口的对象,就无法使用JDK动态代理,转而使用CGlib动态代理生成一个被代理对象的子类来作为代理。

  BeanFactory和ApplicationContext有什么区别?

  1)BeanFactory是Spring里面最底层的接口,包含了各种Bean的定义,读取bean配置文档,管理bean的加载、实例化,控制bean的生命周期,维护bean之间的依赖关系。ApplicationContext接口作为BeanFactory的派生,除了提供BeanFactory所具有的功能外,还提供了更完整的框架功能。

  2)BeanFactroy采用的是延迟加载形式来注入Bean的,即只有在使用到某个Bean时(调用getBean()),才对该Bean进行加载实例化。ApplicationContext是在容器启动时,一次性创建了所有的Bean。这样在容器启动时,我们就可以发现Spring中存在的配置错误,这样有利于检查所依赖属性是否注。

  3)BeanFactory通常以编程的方式被创建,ApplicationContext还能以声明的方式创建,如使用ContextLoader。

  4)BeanFactory和ApplicationContext都支持BeanPostProcessor、BeanFactoryPostProcessor的使用,但两者之间的区别是:BeanFactory需要手动注册,而ApplicationContext则是自动注册。

  Spring AOP/AspectJ AOP的区别?

  1)Spring AOP属于运行时增强,而AspectJ是编译时增强;

  2)Spring AOP基于代理(Proxying),而AspectJ基于字节码操作(Bytecode Manipulation);

  3) AspectJ Spring AOP compared to the more powerful, but Spring AOP is relatively easier. If the cut is relatively small, so little performance difference between the two. However, when cut too much, the best choice for AspectJ, it is much faster than SpringAOP.

  Spring supports several bean scopes?

  1) singleton: By default, each container is only one instance of the bean, the mode is maintained by a single embodiment BeanFactory itself.

  2) prototype: a request instance for each bean.

  3) request: Create an instance of a network for each request, after the request is completed, the bean will fail and garbage collected.

  4) session: the request is similar to the range, to ensure that each session has an instance of the bean, after the session expires, bean failure will follow.

  5) global-session: global scope, global-session related and Portlet application. When your application deployment in the Portlet container, it contains a lot portlet. If you want to declare all of the portlet shared global memory variables, then it needs to be stored in global variables in the global-session. Servlet session scope and global scope in the same effect.

  Of course, different companies for job seekers skills needs will be different, the focus of study are not the same. If you want to learn more about Java job interview skills, you can choose a professional way to learn, help you faster and better into line Java.


Guess you like

Origin blog.51cto.com/14551723/2471133