Framework summary in Java

Source: Internet
Author: User
Tags aop reflection tomcat server

Struts2
    • The nature of Struts2 can be divided into three parts?

A: The core control layer (Filterdispatcher), the Business Control layer (Action), and the user implement the enterprise business logic components.

    • The basic process of Struts2?

(1) The client initializes a request to the servlet container, (2) The request passes through a series of filtering (Filter), (3) then Filterdispatcher is called, Filterdispatcher asked Actionmapper to decide if the request needed to invoke an action, (4) to call a action,filterdispatcher to give the request the processing to Actionproxy ; (5) Actionproxy asks the configuration file of the framework through the Config manager to find the action class that needs to be called; (6) Actionproxy creates an instance of Actioninvocation ; (7) The Actioninvocation instance is invoked using the naming pattern, which involves the call of the Interceptor (Intercepter) before and after the action is invoked, and (8) A little action is executed. Actioninvocation is responsible for finding the corresponding return result according to the configuration in the Struts.xml, (9) The corresponding return is through the filter configured in Web. XML, (10) If Actioncontextcleanup is currently used, the Filterdispatche R will not clean the sreadlocalactioncontext, otherwise it will clean up the sreadlocal;

    • What are the differences between interceptors and filters?

A: (1) The Interceptor is based on the Java reflection mechanism, and the filter is based on the callback function, (2) The interceptor does not rely on the servlet container, the filter relies on the servlet container, and (3) The Interceptor only works on the action request, and the filter can work on almost all requests. (4) The interceptor can access the action context, the object in the value stack, and the filter cannot, (5) in the life cycle of the action, the interceptor can be accessed multiple times, and the filter can only be called once when the container is initialized;

    • Comparison of Struts1 and struts2?

A: (1) Action class: Struts1 requires an action to inherit an abstract base class, a common problem with Struts1 is to use abstract class programming instead of interfaces, STRUTS2 can implement the action interface, and other interfaces can be implemented, making it possible to select and make services, It provides a actionsupport base class to implement the commonly used interface, the action interface is not required, and any Pojo object that is modified by execute can be an action object. (2) Threading mode: The STRUTS1 thread is a singleton mode and is thread-safe because there is only one action to handle the current request. STRUTS2 generates an instance for each request, so there is no thread safety issue. (3) servlet dependency: Struts1 relies on the servlet API, because when an action is called, Httpservletrequset and HttpServletResponse are passed to the Execute method, The Struts2 does not depend on the container, and the run action out of the container is tested separately.

    • What is the core controller of STRUTS2? What role does it have?

Answer: The struts core controller is strutsprepareandexcutefileter. Role: Responsible for intercepting all user requests specified by <url-pattern>/*</url-pattern>, when the user's request arrives, the filter will filter out the user's request. By default, if a user requests a path that does not have a suffix or ends with ". Action", then the request is transferred to the STRUTS2 framework, otherwise the STRUTS2 framework will skip processing the request.

    • How does the STRUTS2 framework manage action? What are the benefits of such a management approach?

A: The STRUTS2 framework uses packages to manage action, and the role of packages is basically similar to the role of class packages in Java, primarily for managing a set of action related to business functions.

    • What is the role of the default package Struts-default in Struts2?

A: (1) Struts-default is built into struts, which defines the many interceptors and result types in the struts2, while many of the core content in Struts2 is implemented through these built-in interceptors. (2) Struts-default is defined in Struts-default.xml, Struts-default.xml is also the default file for Struts2, Struts2 automatically loads struts-default.xml files every time. (3) Usually each package should inherit the Struts-default package.

    • Struts2 How is the specified method validated?

A: (1) The Validate () will have the same method as the Execute method signature in the action, (2) The method specified is to be implemented by overriding the ValidateXxx () method, ValidateXxx () will only be the method named XXX (). (3) When a data validation fails, call the Addfielderror () method to add a validation failure message to the system's fielderrors. (4) The error message can be displayed through <s:fielderror/> in the view. (5) First execute validatexxx ()->validate () If an error occurs, the <result name= "input" > the specified page is forwarded, and if there is no error, execute Action::execute directly () Method.

    • The principle and life cycle of value stack valuestack?

A: (1) Valuestack runs through the entire action lifecycle and is stored in the request domain, and all valuestack have the same life cycle as the request, and when Struts2 accepts a request, The actioncontext,valuestack,action is created quickly. The action is then stored in the Valuestack, and all action instance objects can be accessed by OGNL. When the request comes, Action,valuestack's life begins, the request ends, and Action,valuestack's life ends. (2) Action is multiple, and servlet is not the same, Servlet is a singleton, (3) each action has a corresponding value stack, the value stack holds the data type is the Aciton instance, and the action's instance variable, the action object is saved at the top of the stack by default ; (4) The essence of Valuestack is a ArrayList; (5) When you use OGNL to access the contents of the value stack, you do not need to add the # number, while accessing the request,session,application,attr, you need to add the # number; (6) in struts, OGNL expressions need to be used with struts tags, such as <s:property value= "name"/>. (7) referencing the OGNL expression in the Struts2 configuration file, referring to the value in the value stack, using "$" instead of "#" or "%";

    • The difference between actioncontext,servletcontext,pagecontext?

A: (1) Actioncontext is the context of the current action, and through Actioncontext you get a reference to the object Request,session,serveltcontext equals the action. (2) Serveltcontext is a domain object, there can be only one servletcontext in a Web application, and the life cycle accompanies the Web application. (3) PageContext is an important built-in object of JSP, can get the application of other domain object through PageContext, at the same time it is a domain object, the scope is only for current page, end of current page, PageContext destroy, The life cycle is the smallest of the four objects in a JSP.

Spirng
    • What modules does the Spring framework have?

Answer: Spring core container-IOC container; Spring aop;spring mvc;spring dao;spring orm;spring web;spring Context

    • Why use the spring framework and what are its advantages?

A: (1) lightweight framework, (2) non-invasive, (3) can integrate other frameworks, such as Struts,hibernate, (4) can provide transaction management;

    • What is the working mechanism of the spring framework?

A: (1) Spring MVC gives all of the requests to dispatcherservlet, and it delegates the other modules of the application system responsible for the actual processing of the request. (2) Dispatcherservlet requests one or more haldermapper to find the controller that handles the request. (3) After the controller has processed the business logic, it returns a Modelandview. (4) Dispatcher queries one or more viewresolver (view resolvers) to find the view object specified by the Modelandview object. (5) The View object returns the result to the client.

    • How to use spring things?

A: Spring supports both programmatic and declarative transaction policies, most of which use declarative transaction policies. There are 4 declarative transaction policies: (1) Use Transactionproxyfactorybean to generate the configuration of the transaction agent for the Bean. (2) The method of configuring the transaction proxy with Bean inheritance. (3) The method of generating the transaction agent automatically based on the bean name using Beannameautoproxycreator. This is the way to configure the transaction proxy using the Spring AOP framework, which requires some understanding of spring's AOP. (4) using Defaultadvisorautoproxycreator, directly using the Spring AOP framework to configure the transaction agent, the effect is very good, but less readable than the previous three.

    • Please talk about SSH integration?

Answer: (1) Struts (presentation layer) +spring (business layer) +hibernate (persistence layer). (2) Struts: is a presentation layer framework, mainly used for page display, accepting requests and distributing requests; In the MVC framework, struts belongs to the VC level, responsible for the interface performance, responsible for the distribution of the MVC relationship; view follows Jsp,http. (3) Spring: is a business layer framework that is an integrated framework that nicely adheres to the presentation layer and the persistence layer. (4) Hibernate: is a persistent framework that is responsible for working with relational databases.

    • How is the database driver configured in the Spring framework?

A: Drivermanagerdatasource the data source to configure the database driver.

    • Can the Applicationcontext.xml file be changed to a different file name in the Spring framework?

A: Contextloaderlistener is a servletcontextlistener, and when you start the Tomcat server, It reads the Applicationcontext.xml file under Web-inf and initializes the spring configuration. If you want to modify the filename of the Applicationcontext.xml file or where the file is stored, you can resolve the problem by defining a <context-param> element in the Web. xml file.

    • How do I configure spring in the Web?

For:

    • How do I define hibernate Mapping in spring?

A: Add hibernate mapping files to the Applicationcontext.xml file in the Web-inf directory.

    • Explain dependency injection (DI, Dependency injection) and inversion of control (IOC, inversion of controls)?

A: Dependency injection di is a design pattern, often referred to as inversion of control, although, technically, dependency injection is a special implementation of IOC, dependency injection refers to one object applying another object to provide a special ability. For example, a database connection is passed to the constructor of an object in the form of a parameter instead of automatically creating a connection within that object. Dependency Injection and inversion of control are different descriptions of the same thing, and in one way or another, they describe the angle, dependency injection is described from the perspective of the application, the application relies on the container to create and inject the external resources it needs; control inversion is from the container's point of view in the description, container control application, and the external resources required by the container to inject the application into the application backwards.

    • What are the roles of Beanfactory and ApplicationContext in spring?

A: (1) Beanfactory is responsible for reading the bean configuration document, managing the bean's loading and instantiation, maintaining the dependencies between beans, and responsible for the bean's life cycle. (2) In addition to providing the functions provided by the above Beanfactory, ApplicationContext provides a more complete framework function: A, internationalization support. B, Access resources: Resource Rs=ctx.getresource ("Classpath:config.properties"). C, Event delivery: By implementing the Applictioncontextaware interface. (3) Common ways to get ApplicationContext: Filesystemxmlapplicationcontext: Created from the file system or URL-specified XML configuration file, the parameter is a configuration file name or an array of file names. Classpathxmlapplicationcontext: Created from the classpath XML configuration file, you can read the mate file from the jar package. Webapplicationcontextutils: Reading a configuration file from the Web application's root directory is now configured in XML, and can be configured with a listener or servlet.

<listener>    <listener-class>         Org.springframework.web.context.ContextLoaderListener   </listener-class></listener ><servlet>    <servlet-name>context</servlet-name>    <servelt-class>           org.springframework.web.context.ContextLoaderServlet    </servelt-class>    <load-on-startup>1</load-on-startup></servlet>

    • How to internationalize in spring?

Answer: Configure a Bean in Applicationcontext.xml:

<bean id= "Messagesource"  class="     Org.spirngframework.context.support.ResourceMessageSource "><property name=" basename ">     <value >message</value></property></bean>

In the SRC directory to build multiple properties files, its naming format Message_ language _ country. When the information is displayed in the page, the relevant information is removed by Applicationcontext.getmessage ("Key Name", "parameter", "region").

    • What are the spring core classes, and what are the roles?

A: beanfactory: Create a new instance, you can implement a singleton pattern; Beanwrapper: Provides a uniform get and set method; ApplicationContext: Provides the implementation of the spring framework, Includes all functions of beanfactory;

    • What is the role of AOP,AOP?

A: Aspect-oriented programming (AOP) provides an alternative perspective for thinking about program structure, which compensates for object-oriented deficiencies in this way. In addition to classes, AOP provides transaction management for facets such as crosscutting multiple models and objects. A key component of SPIRNG is the AOP framework, which is free to choose whether to use AOP to provide declarative enterprise services, especially in lieu of EJB declarative services, the most important service being declarative transaction management, which is built on spring's abstract transaction management. Allowing users to customize facets, using AOP to refine the use of OOP, can be seen in spring AOP as an enhancement to spring.

    • What are the benefits of using spring?

A: (1) Spring can effectively organize middle-tier objects, whether you choose to use EJBS or not, if you use struts,spring to focus on legacy issues. (2) Spring can eliminate the excessive use of singleton in many projects. (3) Spring eliminates the need to customize files with attributes in a variety of formats, which can be configured in a consistent way throughout the project. (4) It is possible to promote good programming habits through interfaces rather than classes, reducing programming costs by almost zero. (5) Spring is designed to allow applications created with it to rely on its APIs as little as possible. Most business objects in a spring application are not dependent on spring. (6) Easy unit testing using the Spring framework. (7) Spring can make the use of EJB an implementation choice, not the inevitable choice of application architecture, can choose to use POJOs or local EJBS to implement the business interface, but does not affect the debugging code. (8) Spring solves many problems without using EJBS, for example, spring can use AOP to provide declarative transactions without using an EJB container, if it is just a matter of dealing with a single data, even without the need for a JTA implementation. (9) Spring provides a unified framework for data storage, whether using JDBC or O/R mapping products.

    • What is Spring? What is the characteristic of it?

A: Spring is a lightweight control inversion (IOC) and facet-oriented (AOP) container framework. (1) lightweight : Spring is lightweight both in terms of size and cost. The full spring framework can be published in a jar file of more than 1M size, and spring's processing overhead can be negligible, and spring is non-intrusive: Typically, objects in spring applications do not depend on a particular class of spring. (2) control reversal : Spring facilitates loose coupling by controlling the inverse. When an IOC is applied, other dependent objects of an object are passed in passively, rather than creating or locating dependent objects themselves, it can be assumed that the IOC, contrary to Jndi, is not the object looking for dependencies from the container, but rather that the container proactively passes the dependency to it when the object is initialized. (3) aspect-oriented : Spring provides rich support for aspect-oriented programming, allowing for the development of cohesion through the separation of application business logic and system-level services. The Application object just implements what they should do-complete the business logic-that's all. They are not responsible for other system-level concerns, such as logging or transactional support. (4) container : Spring contains and manages the configuration and life cycle of the Application object, in this sense he is a container that can configure how each bean is created-based on a configurable prototype (property), Beans can create a single instance or generate a new instance each time they need it, and how they relate to each other, however, spring should not be confused with traditional EJB containers, which are often bulky and unwieldy and difficult to use. (5) Framework : Spring can combine simple components and configure them into complex applications. Applying objects in spring is a declarative combination, typically in an XML file, Spring provides a lot of basic functionality (transaction management, persistence framework integration, etc.), leaving the development of application logic to developers.

    • What are some important noun explanations in AOP?

Answer: (1)Facets(aspect): A focus of modularity, this focus may be crosscutting multiple objects. Transaction management is a good example of a crosscutting concern in the Java EE application. In spring AOP, facets can be implemented using generic classes or @aspect annotations in ordinary classes. (2)Connection Point(Joinpoint): a particular point in the execution of a program, such as when a method is called or when an exception is handled. In spring AOP, a connection point represents the execution of a method by declaring a parameter of type org.aspectj.lang.JointPoint to get the connection point information for the body part of the notification (Advice). (3)Notice(Advice) Actions performed on a particular connection point of a slice, with notifications of various types, including "Around", "before", "after" notifications, many AOP models, including spring, are notified by interceptors, and maintains a chain of interceptors centered on the connection point. (4)entry point(Pointcut): matches the assertion of the connection point, notifies the expression associated with a pointcut, and runs on the connection point that satisfies the pointcut. How Pointcut expressions match connection points is the core of AOP: Spring defaults to using the ASPECTJ pointcut syntax. (5)introduced(Introduction): Also known as an internal type declaration. Declaring an extra method or a field of a type, spring runs the introduction of a new interface to any proxied object, for example, you can implement the IsModified interface with a bean to simplify the caching mechanism. (6)target Object(target object): An object that is notified by one or more facets. Also known as the Notified object, since spring AOP is implemented by the runtime proxy, this object is always the object that is being proxied. (7)AOP Agent: An object created by the AOP framework to implement a tangent contract. In spring, an AOP proxy can be either a JDK dynamic agent or a gclib proxy. (8)weave into(Weaving): Connects facets to other application types or objects, and creates a notification object. These can be done at compile time, at class load time, and at run time. Spring, like other pure Java AOP frameworks, completes weaving at run time.

    • Compare the pros and cons of hibernate three search strategies?

A: (1) Search Now: Pros : Fully transparent to the application, whether the object is persistent or free, the application can easily navigate from one object to another object associated with it. disadvantage : There are too many SELECT statements, and it may be a waste of memory space to load objects that the application does not need to access. (2) deferred retrieval: Benefits : The application determines which objects need to be loaded, avoids executing multiple SELECT statements, and avoids loading objects that the application does not need to access, thus improving retrieval performance and saving memory space. disadvantage : An application that accesses an instance of the Free State proxy class must be guaranteed to be initialized when it is persisted. (3) urgent left outer connection search: Advantages : Full transparency of the application, regardless of whether the object is in a persistent state or a free State, the application can easily navigate from one object to another object associated with him, using an outer link, the SELECT statement is reduced. disadvantage : It is possible to load objects that the application does not need to access, waste a lot of memory, and complex data table connections can also affect retrieval performance.

    • What is the difference between sorted collection and ordered collection in hibernate?

A: Sorted collection is sorted in memory by the Java comparer; ordered Conllection is sorted in the database through ordered by.

    • Hiberante working principle and why should I use it?

A: The principle : Read and parse the configuration file, read and parse the mapping information, create sessionfactory; open session; Create transaction transation; persist operation; COMMIT TRANSACTION; Close session Closed sessionfactory; why : (1) The Code of JDBC Access database is encapsulated, which greatly simplifies the tedious repetitive code of the data Access layer; (2) Hibernate is a main JDBC-based persistence framework. is a good ORM implementation, greatly simplifies the coding of the DAO work; (3) Hibernate uses the Java reflection mechanism rather than the bytecode enhancer to achieve transparency, and (4) supports various database relationships, from one-to-one to many-to-many complex relationships;

    • How to optimize hibernate?

A: (1) The use of two-way one-to-many association, do not use single-to-many, (2) Flexible use of unidirectional-to-many associations; (3) No one-to-many substitution; (4) Configuring the object cache, not using the collection cache, (5) using Bag with multiple sets for multiple collections, and (6 ; (7) Table field is very few, the list is not afraid of more, there are two levels of cache;

    • What are the different query modes for hibernate?

Answer: HQL, conditional query (QBC), native SQL;

    • What is the difference between the update () and Saveorupdate () methods in Hibernate?

A: The Saveorupdate method can implement the functionality of the Update method, but more steps, such as: If the object has been persisted in the session, do not operate; The identifier property of the object does not exist in the database or is a temporary value, call the Save () method to save it An exception is thrown if the object in the session has the same identifier, and none of the above matches the call to the Update method.

    • What is the difference between get () and load () in the session?

A; If no qualifying records are found, the Get method returns NULL, and the load method throws an exception Objectnotfoundexception;load method can return an instance of the entity's proxy class, and the Get method always returns the entity class directly The Load method can take full advantage of the existing data in the internal cache and the level two cache, while the Get method only makes the data lookup in the internal cache, and if no data is found, it passes through the level two cache and directly invokes SQL to complete the data read.

    • What are the benefits of free objects (Detached object)?

A: The free object can be passed to any layer until the presentation layer rather than using any dto, then you can also reassign the free object to another session.

Framework summary in Java

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.