Java face test-frame eight
71, talk about your understanding of struts.
1. Struts is a web-layer framework designed in the MVC pattern, which is actually a servlet, the servlet named Actionservlet, or a subclass of Actionservlet. We can hand over all requests that meet a feature in the Web.xml file to this servlet, which then refer to a configuration file to assign each request separately to the different action.
(struts can have more than one configuration file, you can configure their own profiles by module, which prevents excessive expansion of the configuration file)
2.ActionServlet the request parameter is encapsulated into a Formbean object (just a Java class, each attribute in the class corresponds to a request parameter) before it is processed by the action.
3. To illustrate, Actionservlet may invoke the Validate method of Formbean to verify that the Formbean object is passed to the Execute method of the action. This Formbean object is passed to the Execute method of the action only after the checksum is passed, otherwise it returns an error page, which is specified by the input property.
4.action to return to the displayed result view after execution, the result view is represented by a Actionforward object. The Actionforward object is associated with a JSP page through the configuration in the Struts-config.xml configuration file, because the program uses a logical name that is set up in the Struts-config.xml profile for the JSP page, which enables the action program code and the returned JSP page The decoupling of the face name.
(above, can also be combined with their own feelings to talk about their own views)
72, talk about your understanding of hibernate.
1. object-oriented design software internal operation process can be understood to be in the continuous creation of new objects, establish the relationship between objects, call the object of the method to change the state of each object and object extinction process, no matter how the process and operation of the program, essentially are to get a result, The difference in the running results of a time and the next moment in the program is reflected in the state of the object in memory that has changed.
2. In order to maintain the running state of the program in the condition of shutdown and insufficient memory space, it is necessary to save the state of the object in memory to the persistent device and restore the state of the object from the persistent device, usually to save a large amount of object information in the relational database. From the operational functions of Java programs, the function of saving object state should be a very obscure subsidiary function compared with other functions of system running, the Java uses JDBC to implement this function, but the obscure function is to write a lot of code, and the thing to do is to save object and recover object only, And the large number of JDBC code is not a technical content, basically a set of routine standard code template to write, is a hard work and repetitive job.
3. To save the objects and recover objects generated by the Java program running through the database, it is the mapping relationship between Java objects and relational database records, called ORM (i.e. object relationmapping), which can be implemented by encapsulating the JDBC code. Packaged products are called ORM Frameworks, and Hibernate is one of the popular ORM frameworks. Using the Hibernate framework, instead of writing the JDBC code, simply calling 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 of using Hibernate is to configure Configuration objects, generate Sessionfactory, create session objects, start transactions, complete crud operations, commit transactions, and close session.
5. When using Hibernate, To configure the Hibernate.cfg.xml file, where you configure database connection information and dialects, and configure the corresponding Hbm.xml files for each entity, you need to register each hbm.xml file in the Hibernate.cfg.xml file.
6. When applying hibernate, it is important to understand the caching principle of Session, cascade, delay load and HQL query.
(above, can also combine their use of JDBC when the tedious talk about hibernate feelings)
73, talk about your understanding of spring.
1.Spring is the factory class that implements the factory pattern (where it is necessary to explain what the factory pattern is), the class is named Beanfactory (actually an interface), and the subclass ApplicationContext in the program is usually beanfactory. 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 the IOC, which is a programming idea and an architectural art that can be used to decouple the modules well, and the IOC is also called DI (depency injection).
3. Spring provides a good encapsulation of AOP technology, AOP, referred to as aspect-oriented programming, is a system in which there are many disparate classes of methods in which the code to add some system functionality, such as adding a log, adding permission judgments, and adding exception handling, is called AOP.
The implementation of the AOP function is the proxy technology, the client program no longer calls the target, while calling the proxy class, the proxy class and the target class have the same method declaration, there are two ways to implement the same method declaration, one is to implement the same interface, and the second is a subclass of the target.
Using the proxy class to generate a dynamic proxy in the JDK generates the implementation class for an interface, and if you want to generate subclasses for a class, you can use Cgli B. In the generated proxy class method, the system function and the corresponding method of calling the target class are added, the proxy of the system function 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 simply configuring the two elements in the spring configuration file to implement proxy and AOP capabilities.
(above, can also be combined with their own feelings to talk about their own views)
74, talk about the pros and cons of struts
Advantages:
1. Implementation of the MVC pattern, the structure is clear, so that developers only focus on the implementation of business logic.
2. There is a wealth of tag can be used, struts of the tag library (Taglib), if flexible to use, can greatly improve the development efficiency
3. Page navigation makes the system more clear in its context. Through a configuration file, you can grasp the whole system of the relationship between the parts, which for the maintenance of the latter has great benefits. This is especially true when another group of developers takes over the project.
4. Provide exception processing mechanism.
5. Database Link Pool Management
6. Support i18n
Disadvantages:
First, go to the presentation layer, you need to configure forward, if there are 10 display layer of JSP, need to configure 10 times struts, but also does not include some of the directory, file changes, you need to modify the forward, note that every time you modify the configuration, requires redeployment of the entire project, Servers such as Tomcate must also reboot the server
Second, the action of struts must be thread-safe, which allows only one instance to handle all requests. So all the resources that the action uses must be synchronized uniformly, which raises the issue of thread safety.
Third, the test is inconvenient. Each action of struts is coupled with 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 struts testcase that can implement its unit tests.
Four, types of conversions. Struts Formbean all data as String types, and it can be converted using tool commons-beanutils. But its transformation is at class level, and the type of transformation is not configurable. It is also very difficult to return the error message to the user when the type is converted.
Five, the servlet dependency is too strong. Struts must rely on servletrequest and servletresponse to handle the action, all of which will not be able to escape the servlet container.
Six, front end expression language aspect. Struts integrates jstl, so it mainly uses the JSTL expression language to get the data. However, the JSTL expression language is weak in terms of collection and indexed properties.
Seven, the control of action execution is difficult. Struts creates an action that can be very difficult if you want to control the order in which it is executed. Even you have to write the servlet again to achieve this functional requirement.
The processing of the action before and after execution. When struts handles the action, it is based on class hierarchies, which is difficult to manipulate before and after the action is processed.
Nine, insufficient support for events. In struts, it's actually a form form that corresponds to an action class (or Dispatchaction), in other words: in struts it is actually a form that corresponds to only one event, Struts this type of event is known as a coarse-grained event compared to application Event,application and component events
What's the difference between 75,ibatis and hibernate?
The same point: masking the low-level access details of the JDBC API, and accessing the data using the JDBC API we don't have to deal with.
JDBC API programming process is fixed, and the SQL statements are mixed with Java code, often need to cobble together SQL statements, the details are cumbersome.
Ibatis Benefits: Masks The low-level access details of the JDBC API, separates the SQL statements from Java code, and provides 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 the entity object to the 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 ibatis functions. Because hibernate automatically generates SQL statements, we cannot control the statement, and we cannot write specific, efficient SQL. For some less complex SQL queries, hibernate can help us to complete, but for particularly complex queries, hibernate is difficult to adapt, this time with Ibatis is a good choice, because Ibatis or by ourselves to write SQL statements.
76, in Hibernate for multiple table query each table to take a few fields, that is, query out of the result set does not have an entity class corresponding to how to solve.
Solution One: Remove the data according to the object[] data, and then group your own bean
Solution Two: The Bean write constructor for each table, such as table one to find out field1,field2 two fields, then one constructor is the bean (type1filed1,type2
Field2), and then you can generate this bean directly inside the HQL.
77, introduce the Hibernate level two cache
Follow these lines to answer:
(1) First clear what is the cache
(2) Besides, the session with Hibernate is a first-level cache, that is, there is a level of cache, why there is a level two cache
(3) Finally, how to configure the Hibernate level two cache.
1, caching is to save the previously queried and used objects from the database in memory (a data structure), this data structure is usually or similar to HashMap, when you want to use an object in the future, query the cache for this object, if there is the use of objects in the cache, If not, query the database and save the queried object in the cache for next use.
2,hibernate session is a cache, we usually call it a 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 this object, the existence is directly returned, Does not exist to access the database and to save the results of the query within itself.
Because the session represents a conversation process, and a sessions are associated with a database connection, it is best not to keep it open for a long time, usually for one transaction only, and close at the end of the transaction. And the session is thread-insecure and is prone to problems when shared by multiple threads. Usually only that the global sense of the cache is the real cache application, there is a large cache value, therefore, the hibernate session of this cache cache effect is not obvious, the application of little value. Hibernate's level Two cache is to configure a global cache for hibernate, allowing multiple threads and multiple transactions to share the cache. We want to be used by one person, other people can also use, the session does not have this effect.
3, the level two cache is independent of hibernate software parts, products belonging to third parties, many vendors and organizations provide cache products, such as Ehcache and Oscache, and so on. Using level two caching in Hibernate, The first step is to configure which manufacturer's cache product is used in the Hibernate.cfg.xml configuration file, then configure the cache product's own profile, and finally configure which entity objects in the hibernate to be included in the level two cache management. Understand the two-level caching principle and with this idea, it is easy to configure the hibernate level two cache.
Extended knowledge: A sessionfactory can associate a level two cache, or a level two cache can only be responsible for caching data in a database, and when using the hibernate level two cache, Be careful not to have other applications or sessionfactory to change the data in the current database, so that the cached data is inconsistent with the actual data in the database.
What is 78,JDO?
JDO is a new specification for Java Object Persistence, abbreviated 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 the developer to focus time and effort on the business logic. In addition, JDO is flexible because it can run on any underlying data.
Comparison: JDBC is more generic to relational database (RDBMS) JDO, providing storage functionality at the bottom of any data, such as relational databases, files, XML, and Object Databases (Odbms), and so on, making applications more portable.
79,hibernate the difference between one-to-many and many-to-many pairs of two-way associations.
The basic principle of the realization of One-to-many Association Mapping and Many-to-many correlation mapping is the same, which is to add a foreign key at one end to the other, and the main difference is that the maintenance end is different.
The difference is that they maintain different relationships:
A One-to-many association mapping is a data that loads one end of one end of a data, and a many-to-many correlation map is the data that loads a single end of the data at the end of the load.
How does the 80,hibernate delay loading?
1. Hibernate2 Deferred load implementation: a) collection of entity object B (Collection)
2. Hibernate3 provides delayed loading of properties when the Hibernate queries the data, the data does not exist in memory, and when the program is actually operating on the data, the object exists and is in memory, it realizes the delay loading, and he saves the memory cost of the server, Thus improving the performance of the server.
Java Companion public number of major companies to organize a number of commonly used interview pen questions, for everyone in the spare time to learn some of the topics, accumulated over time, wait for the interview, everything is ripe, the interview will naturally be easier.