Java Framework Interview 2

Source: Internet
Author: User
Tags to domain

1. Talk you to Struts's Understanding .

For:

1. Struts is a web-layer framework designed by MVC pattern, which is a large servlet, called Actionservlet, or Actionservlet subclass. In the Web. xml file, we can hand over all requests that match a certain feature to the servlet, which references a configuration file (typically/web-inf/ Struts-config.xml) Each request is assigned to a different action to handle.

An extension of knowledge points: struts can have more than one configuration file, can be configured according to the module configuration file, so as to prevent excessive expansion of the configuration file;

2. Actionservlet the request parameters into a Formbean object (that is, a Java class, each attribute in the class corresponds to a request parameter), and encapsulates it into what kind of Formbean object before handing the request to the action? Look at the configuration file.

3. To illustrate, Actionservlet may call Formbean's Validate method for validation before passing the Formbean object to the action's Execute method. The Formbean object is passed to the action's Execute method only after the checksum is passed, otherwise it returns an error page that is specified by the input property, (see Configuration file) Why did the author name This here the input property instead of the error property, We analyze the actual running effect behind us.

4.action to return the displayed result view after execution, the result view is represented by a Actionforward object, The Actionforward object is associated to a JSP page through the configuration in the Struts-config.xml configuration file because the program uses the logical name set in the Struts-config.xml profile for the JSP page, which enables the action program code to be implemented with the returned JSP page Decoupling of the face name.

Your experience with struts may also have its own application, and that should be said as well.

2. Talk you to hibernate of the Understanding .

For:

1. Object-oriented design of the internal operation of the software can be understood to be in the continuous creation of new objects, the relationship between objects, call the method of the object to change the state of the object and the object of the process of extinction, regardless of the process and operation of the program, essentially to get a result, The difference in the running result of a time and the next moment in the program is a change in the state of the object in memory.

2. In order to maintain the running state of the program in the case of shutdown and insufficient memory space, it is necessary to save the state of the object in memory to the persistence device and restore the state of the object from the persistence device, usually saving the large amount of object information to the relational database. From the running function of Java program, the function of saving object state, compared with other functions of the system, should be a very humble subordinate function, Java uses JDBC to achieve this function, this humble function is to write a lot of code, and do is only to save objects and restore objects, And the large number of JDBC code does not have any technical content, basically is a set of routine standard code template to write, is a kind of hard work and repetitive work.

3. Save the object and restore object from the Java program runtime through the database, actually realize the mapping relation between Java object and relational database record, called ORM (that is, Object Relation Mapping), people can realize this function by encapsulating the JDBC code. The encapsulated product is called an ORM framework, and Hibernate is one of the popular ORM frameworks. Using the Hibernate framework, instead of writing the JDBC code, simply invoking a save method, you can save the object to a relational database, and simply call a GET method to load an object from the database.

4. The basic process for using Hibernate is to configure a configuration object, generate Sessionfactory, create a Session object, start a transaction, complete a crud operation, commit a transaction, and close the session.

5. When using Hibernate, To configure the Hibernate.cfg.xml file first, configure the database connection information and dialect, and configure the corresponding Hbm.xml file for each entity, you need to register each hbm.xml file in the Hibernate.cfg.xml file.

6. When applying hibernate, focus on understanding the session's caching principles, cascading, lazy loading, and hql queries.

3. The role of AOP .

4, you to S Pring of the Understanding .

1.Spring implements factory-mode factory classes (where it is necessary to explain what is Factory mode), the class named Beanfactory (actually an interface), which is usually beanfactory subclass ApplicationContext in the program. Spring is the equivalent of a large factory class that configures the properties of the class name and instance object used to create the instance object in its configuration file through the <bean> element.

2. Spring provides good support for IOC, the IOC is a programming idea, is an architectural art, the use of this idea can be a good way to achieve decoupling between modules. IOC is also called DI (depency injection), what is dependency injection?

For example, Class Programmer

{

Computer computer = NULL;

public void Code ()

{

Computer computer = new Ibmcomputer ();

Computer computer = Beanfacotry.getcomputer ();

Computer.write ();

}

public void Setcomputer (computer computer)

{

This.computer = computer;

}

}

The other two approaches are dependent, the first directly depends on the target class, the second shifts the dependency to the factory, and the third is completely decoupled from the target and factory. Configure the snippet in the spring configuration file as follows:

<bean id= "Computer" class= "Cn.itcast.interview.Computer" >

</bean>

<bean id= "programmer" class= "Cn.itcast.interview.Programmer" >

<property name= "Computer" ref= "Computer" ></property>

</bean>

3. Spring provides a good encapsulation of AOP technology, AOP is called aspect-oriented programming, is the system has a lot of unrelated classes of methods, in these many methods to add a system function code, for example, join the log, add permission to judge, add exception processing, this application is called AOP. The implementation of the AOP function is the agent technology, the client program is no longer called the target, and the call proxy class, the proxy class and the target class has the same method declaration, there are two ways to implement the same method declaration, one is to implement the same interface, the second is the target subclass in, In the JDK, the proxy class is used to generate a dynamic proxy to produce an implementation class for an interface, and if you want to generate subclasses for a class, you can use Cgli B. In the method of the generated proxy class to add the system function and call the corresponding method of the target class, the system function agent is provided by the advice object, obviously to create the proxy object, at least the target class and the advice class are required. Spring provides this support by configuring these two elements in a spring configuration file to implement proxy and AOP functions, for example,

<bean id= "proxy" type= "Org.spring.framework.aop.ProxyBeanFactory" >

<property name= "target" ref= "" ></property>

<property name= "advisor" ref= "" ></property>

</bean>

5. talk about the action servlet in struts.

6. struts pros and cons

Advantages :

1. Implement the MVC pattern with a clear structure that allows developers to focus only on the implementation of the business logic.

2. With a rich tag can be used, struts of the tag library (Taglib), if flexible to use, it can greatly improve the development efficiency

3. Page Navigation

Make the system's context clearer. Through a configuration file, you can grasp the connection between the parts of the whole system, which is of great benefit to the later maintenance. This is especially true when another group of developers took over the project.

4. Provide exception processing mechanism.

5. Database Link Pool Management

6. Support i18n

Disadvantages

First, to go to the presentation layer, you need to configure the forward, if there are 10 display layer of the JSP, need to configure 10 struts, but also does not include sometimes directories, file changes, need to re-modify the forward, note that each time the configuration is modified, the request to redeploy the entire project, Servers such as Tomcate must also restart the server

Two or two, Struts action must be thread-safe mode, it only allows one instance to handle all requests. So all the resources that the action uses must be synchronized uniformly, which raises the thread-safety issue.

Third, the test is not convenient. Each of struts's actions is coupled to the web layer so that its tests depend on the Web container and unit tests are difficult to implement. However, there is a junit extension tool that struts testcase can implement for its unit testing.

Iv. types of conversions. The Formbean of struts takes all the data as a string type, which can be converted using the tool commons-beanutils. However, it is converted at the class level, and the type of conversion is not configurable. It is also very difficult to return the error message to the user when the type is converted.

V. The dependency on the servlet is too strong. Struts must rely on servletrequest and servletresponse when handling action, all of which are not able to get rid of the servlet container.

Vi. front-end expression language aspects. Struts integrates Jstl, so it uses the JSTL expression language primarily to get data. But Jstl's expression language is weak in terms of collection and indexed properties.

Vii. control of action execution is difficult. Struts creates an action, which can be very difficult if you want to control the order in which it is executed. You'll even have to write the servlet again to implement your functional requirements.

Eight, the action to perform before and after the processing. Struts handles action as a class-based hierarchies, which makes it difficult to operate before and after action processing.

Nine, the incident support is not enough. In struts, it is actually a form form that corresponds to an action class (or Dispatchaction), in other words: in struts it is actually a form that only corresponds to one event, and struts is called the application event, Application events is a coarse-grained event compared with component event

7. Struts applications (e.g. struts architecture)

Struts is an open-source framework that uses Java Servlet/javaserver pages technology to develop Web applications. Using struts can develop an application architecture based on the MVC (Model-view-controller) design pattern. Struts has the following main functions: one. Contains a controller servlet that can send a user's request to the appropriate action object. Two. JSP free tag library, and provide associated support in the controller servlet to help developers create interactive form applications. Three. Provides a series of practical objects: XML processing, automatic processing of JavaBeans attributes via Java Reflection APIs, internationalization hints and messages.

8, talk about the difference between struts1 and struts2 .

1. Are all MVC web frameworks,

2 Struts1 's old-style framework, the application is very extensive, has a very good mass foundation, uses it to develop the risk is very small, the cost is lower! Struts2 Although based on this framework, but the application of the masses and more, relatively immature, unknown risk and change a lot, developers relatively bad recruit, use it development projects risk coefficient is greater, employing higher cost!

After all, 3.struts2 is standing in the predecessor of the basic design, it will improve and improve some defects in struts1, struts1 some outstanding issues in the struts2 have been resolved.

4.STRUTS1 's front controller is a servlet, and the front-end controller named Actionservlet,struts2 is a filter, In the struts2.0 called Filterdispatcher, in struts2.1 called Strutsprepareandexecutefilter.

The action of the 5.STRUTS1 needs to inherit the action class, and the action of Struts2 does not inherit any classes; Struts1 all requests to the same path share an action instance, STRUTS2 uses a separate action instance object for each request to the same path, and all actions for struts2 do not take into account thread safety issues.

6. Using the Formbean encapsulation request parameter in Struts1, use the action's property directly in Struts2 to encapsulate the request parameter.

When multiple business methods in 7.struts1 are placed in an action (that is, when the dispatchaction is inherited), either checksum is either not verified, and for struts2, you can specify that only one method is validated. When an action inherits Actionsupport and only the ValidateXxx () method is written in this class, only the XXX () method is validated.

(a request for an execution flow analysis, STRUTS2 is automatically support sub-module development, and can be different modules to set different URL prefixes, which is implemented through the package of namespace; Struts2 is supported by multiple types of views Struts2 View address can be dynamic, that is, the name of the view is the way to support variables, for example, forum post failure to return to pass Boardid. View content display aspect: its label with OGNL, to El powerful many, in internationalization support sub-module management, two modules used to the same key, corresponding to different messages;)

Unlike Struts1, Struts2 creates an action for every request to a user, so the action in STRUTS2 is thread-safe.

What impresses me most is that the URL of the redirect view in the Struts configuration file cannot accept parameters, and the redirect view in the Struts2 configuration file can accept parameters.

9. The difference between update () and Saveorupdate () in Hibernate, the difference between the load () and get () of the session.

10. describe the pros and cons of Hibernate and JDBC? How to write a one to many configuration file.

11. What is the difference between Ibatis and hibernate?

The same point: masking the underlying access details of the JDBC API, using our ability to access data without dealing with the JDBC API.

The JDBC API programming process is fixed, and SQL statements are mixed with Java code, often with a patchwork of SQL statements, and the details are cumbersome.

Ibatis Benefits: Masking The underlying access details of the JDBC API, separating the SQL statement from the Java code, providing the ability to automatically encapsulate the result set as a collection of entity objects and objects, queryForList returns a collection of objects, Returns a single object with queryForObject, and provides parameters that automatically pass the properties of an entity object to an SQL statement.

Hibernate is a fully automated ORM mapping tool that automatically generates SQL statements, Ibatis requires us to write SQL statements in XML configuration files, and hibernate is more responsible and powerful than the Ibatis feature. Because hibernate generates SQL statements automatically, and we can't control the statement, we can't write a specific high-efficiency SQL. For some of the less complex SQL queries, hibernate can be very good for us to do, but for particularly complex queries, hibernate is difficult to adapt to, this time with Ibatis is a good choice, because ibatis or we write SQL statements.

12. Write Hibernate A one-to-many and many-to-two bidirectional association ORM configuration ?

9. The role of Hibernate's inverse attribute ?

Solution One, extract the data according to object[] data, and then own the group Bean

Solution two, for each table bean write constructor, such as table one to find out field1,field2 two fields, then there is a constructor is the bean (type1 filed1,type2

Field2), then you can generate the bean directly inside the HQL.

13. How to embody DAO design pattern in DAO ?

Solution One, extract the data according to object[] data, and then own the group Bean

Solution two, for each table bean write constructor, such as table one to find out field1,field2 two fields, then there is a constructor is the bean (type1 filed1,type2

Field2), then you can generate the bean directly inside the HQL.

14, Spring+hibernate How to configure the program ?

Solution One, extract the data according to object[] data, and then own the group Bean

Solution two, for each table bean write constructor, such as table one to find out field1,field2 two fields, then there is a constructor is the bean (type1 filed1,type2

Field2), then you can generate the bean directly inside the HQL.

15, Spring+hibernate How to configure the program ?

Solution One, extract the data according to object[] data, and then own the group Bean

Solution two, for each table bean write constructor, such as table one to find out field1,field2 two fields, then there is a constructor is the bean (type1 filed1,type2

Field2), then you can generate the bean directly inside the HQL.

More than one table query each table takes several fields, that is, the query results set does not have an entity class corresponding to how to solve;

Solution One, extract the data according to object[] data, and then own the group Bean

Solution two, for each table bean write constructor, such as table one to find out field1,field2 two fields, then there is a constructor is the bean (type1 filed1,type2

Field2), then you can generate the bean directly inside the HQL.

17. Introduce Hibernate's level two cache

Answer according to the following ideas: (1) First of all to clarify what is the cache, (2) and then the hibernate session is a primary cache, that is, there is a cache, why there is a two-level cache, (3) and finally how to configure Hibernate's two-level cache.

(1) The cache is to save objects previously queried from the database and used in memory (a data structure), this data structure is usually or similar to HashMap, when you want to use an object in the future, the first query in the cache whether there is this object, if there is to use the object in the cache, If not, query the database and save the queried object in the cache for the next use. Here is the pseudo-code for the cache:

The second level cache of Hibernate is drawn, and the implementation principle of the cache is analyzed with the following pseudo code

Dao

{

HashMap map = new map ();

User getUser (integer ID)

{

User user = Map.get (ID)

if (user = = null)

{

user = Session.get (ID);

Map.put (Id,user);

}

return user;

}

}

Dao

{

Cache cache = NULL

Setcache (Cache cache)

{

This.cache = cache

}

User getUser (int id)

{

if (cache!=null)

{

User user = Cache.get (ID);

if (user ==null)

{

user = Session.get (ID);

Cache.put (Id,user);

}

return user;

}

return Session.get (ID);

}

}

(2) Hibernate session is a kind of cache, we usually call it hibernate cache, when you want to use the session from the database to query an object, the session is to see from their own internal existence of the object, the existence is directly returned, Does not exist to access the database and save the query's results inside itself. Since the session represents a conversation process, and the sessions are associated with a database connection, the session is best not to remain open for long periods of time, usually only for one transaction, and should be closed at the end of the transaction. And the session is thread insecure, and being shared by multiple threads is prone to problems. Usually only the global sense of the cache is the real cache application, there is a large cache value, therefore, hibernate session of this cache cache role is not obvious, the application is not very valuable. Hibernate's Level Two cache is a global cache configured for Hibernate, allowing multiple threads and multiple transactions to share this cache. We want a person to use it, others can use it, and the session doesn't have that effect.

(3) Level two caches are software parts that are independent of hibernate, products that belong to third parties, and multiple vendors and organizations provide caching products, such as Ehcache and Oscache, and so on. Using a level two cache in Hibernate, The first step is to configure which manufacturer's cache product to use in the Hibernate.cfg.xml configuration file, then configure the cache product's own configuration file, and finally configure which entity objects in Hibernate are to be included in the management of level two cache. Understanding the two-level caching principle and with this idea, it is easy to configure Hibernate's level two cache. Extended knowledge: A sessionfactory can be associated with a level two cache, or a level two cache can only be responsible for caching data in a database, when using Hibernate's Level two cache, Be careful not to have other apps or sessionfactory to change the data in the current database, so that the cached data will not be consistent with the actual data in the database.

18. what does Spring's dependency injection mean? Give a Bean a message property, a string type, an XML configuration file that injects a value of "Hello" How to write it?

19. What is JDO?

JDO is a new specification for Java object Persistence, the abbreviation for Java data Object, and a standardized API for accessing objects in a data warehouse. JDO provides transparent object storage, so for developers, storing data objects does not require additional code (such as the use of the JDBC API). These tedious routines have shifted to the JDO product provider, freeing developers to focus time and energy on business logic. In addition, the JDO is flexible because it can run on any data underlying. JDBC is a more generic, relational database (RDBMS) JDO that provides storage capabilities to any underlying data, such as relational databases, files, XML, and Object Databases (Odbms), and so on, making application portability even stronger.

1.Hibernate working principle and why use?
How it works: 1. Read and parse the configuration file 2. Read and parse the mapping information, create Sessionfactory 3. Open Session 4. Create transaction transation 5. Persist Operation 6. COMMIT TRANSACTION 7. Close Session 8. Close Sesstionfactory
Why to use: 1. The code for JDBC access to the database is encapsulated, which greatly simplifies the tedious repetitive code of the data access layer. 2. Hibernate is a JDBC-based, mainstream persistence framework that is an excellent ORM implementation. He greatly simplifies the coding work of the DAO Layer 3. Hibernate uses the Java reflection mechanism rather than the bytecode enhancer to achieve transparency. 4. Hibernate performs very well because it is a lightweight framework. The flexibility of the mapping is excellent. It supports a variety of relational databases, from one-to-one to many-to-many complex relationships.

2. How does hibernate delay loading?
1. Hibernate2 Deferred load implementation: a) collection of entity object B) (Collection)
2. Hibernate3 provides deferred loading of properties when hibernate queries the data, the data does not exist in memory, and when the program actually operates on the data, the object exists in memory, and the delay is loaded, saving the server's memory overhead. This improves the performance of the server.

3. How do the relationships between classes be implemented in hibernate? (e.g. one-to-many, many-to-many relationships)
The relationship between classes and classes is mainly manifested in the relationship between tables and tables, and they operate on objects, and in our program we map all the tables and classes together, through the Many-to-one, One-to-many, many-to-many in the configuration file.

4.struts1 Process:
1. The client browser makes an HTTP request. 2, according to the Web. XML configuration, the request was Actionservlet received. 3, according to the Struts-config.xml configuration, actionservlet the parameters in the request to Actionform, and then actionservlet send the request to the action for processing. 4, whether to verify, need to verify the call Actionform's Validate method, the validation fails to jump to input, success continues. 5. Action obtains data from Actionform and invokes the business method in JavaBean to process the data. 6. Action returns the Actionforward object and jumps to the corresponding JSP page or action. 7. Returns the HTTP response to the client browser.

MVC design Pattern: modal: "Model" is also called business logic, is the code of the true completion of the task, quite with Javabeanview: view, is actually the display interface, equivalent to Jspcontroller: Controller, he controls the model and view of the interactive process, Equivalent to Servletstruts1 is based on the MVC design pattern hibernate is an ORM object-relational mapping

What is 5.struts?
Struts1 is an open-source Web application framework based on JSP and servlet, using the MVC design pattern struts2 is a framework based on webwork technology, a very well-equipped framework developed by Sun and WebWork. Struts2 and Struts1 have nothing to do with a whole new framework

What is 6.spring?
Spring is a hodgepodge of integrated third-party frameworks with the core technology of IOC (control inversion, also known as Dependency injection) and AOP (tangent-oriented programming)

What is 7.hibernate?
Hibernate is a tool for data persistence based on ORM Object Relational mapping (the mechanism of accomplishing object data to relational data mapping).

What is 8.JSF?
JavaServer face is a component-based Web development framework, similar to the Sturts framework

9. What are the indexes and constraints within the database?
Index is to improve the speed of data retrieval, the index is built on the data table, based on one or more fields to establish the constraints are to maintain the integrity of the data, constraints have non-null constraints, PRIMARY KEY constraints, foreign key constraints and so on.

What is 10.spring?
This problem can often be cut through why we use Spring: AOP allows developers to create non-behavioral concerns, called crosscutting concerns, and insert them into application code. With AOP, public services (such as logs, persistence, transactions, and so on) can be decomposed into facets and applied to domain objects without increasing the complexity of the object model of the domain object. IOC allows you to create an application environment where objects can be constructed, and then pass their collaboration objects to those objects. As the word inversion shows, the IOC is like the reverse JNDI. Not using a bunch of abstract factories, service locators, single elements (singleton), and direct constructs (straight construction), each object is constructed with its collaboration objects. Therefore, the collaboration object (collaborator) is managed by the container. Spring even an AOP framework, is also an IOC container. The best part of Spring is that it helps you replace objects. With Spring, you simply add dependencies (collaboration objects) with the JavaBean property and configuration file. You can then easily replace collaboration objects with similar interfaces when you need them.

11. Use your own words to briefly describe the STRUTS2 implementation process.
The Struts 2 framework itself can be broadly divided into 3 parts: The core controller filterdispatcher, the Business controller action, and the enterprise business logic components implemented by the user. The core controller Filterdispatcher is the foundation of the Struts 2 framework and contains the control flow and processing mechanisms within the framework. Business controller action and business logic components are required to be implemented by the user. While developing the action and business logic components, the user also needs to write the relevant configuration files for use by the core controller filterdispatcher.

The work flow of struts 2 is simpler than struts 1 and basically the same as the webwork framework, so struts 2 is the upgraded version of WebWork. The basic brief flow is as follows: 1. The client browser makes an HTTP request. 2, according to the Web. XML configuration, the request was Filterdispatcher received. 3, according to the Struts.xml configuration, find the action class and method that need to be called, and through the IOC way, the value is injected to Aciton. 4. Action invokes the business logic component to process the business logic, which includes form validation. 5, the action is completed, according to the configuration in the Struts.xml to find the corresponding result of the return, and jump to the corresponding page. 6. Returns the HTTP response to the client browser.

Java Framework Interview 2

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.