In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the framework interview questions for Java". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the framework interview questions for Java"?
71, talk about your understanding of Struts.
1. Struts is a Web layer framework designed according to the MVC pattern. In fact, it is a Servlet. The Servlet is called ActionServlet, or a subclass of ActionServlet. We can hand over all requests that meet certain characteristics to this Servlet in the web.xml file, and the Servlet then assigns each request to a different action for processing according to a configuration file.
(there can be multiple configuration files for struts, and each profile can be configured on a module-by-module basis, which prevents excessive expansion of configuration files.)
Before handing over the request to action, 2.ActionServlet encapsulates the request parameters into a formbean object (that is, a java class, where each property corresponds to a request parameter).
3. To be clear, before ActionServlet passes the formbean object to the execute method of action, it may call the validate method of formbean for verification, and pass the formbean object to the execute method of action only after the verification is passed, otherwise, it will return an error page specified by the input property.
After the 4.action execution, it returns the displayed result view, which is represented by an ActionForward object, which is associated with a jsp page through the configuration in the struts-config.xml configuration file, because the program uses the logical name set for the jsp page in the struts-config.xml configuration file, which can decouple the action program code from the returned jsp page name.
(above, you can also talk about your views with your own experience.)
72. Talk about your understanding of Hibernate.
1. The internal running process of object-oriented design software can be understood that achievement is constantly creating all kinds of new objects, establishing the relationship between objects, and calling object methods to change the state of each object and the process of object demise. No matter what the process and operation of the program is, it is essentially to get a result. The difference between the running result of the last moment and the next moment of the program is shown in the change of the state of the object in memory.
two。 In order to maintain the running state of the program under the condition of shutdown and insufficient memory space, it is necessary to save the object state in memory to the persistence device and recover the object state from the persistence device. it is usually saved to a relational database to store a large amount of object information. In terms of the running function of the Java program, the function of saving the object state should be a very inconspicuous accessory function compared with other functions run by the system. Java uses jdbc to achieve this function, but this humble function requires a lot of code to write, and all it does is to save and restore objects, and that large amount of jdbc code is not very technical. It is basically written using a set of standard code templates that are routine, which is a kind of hard work and repetitive work.
3. Saving objects and recovery objects when java programs are running through the database actually realizes the mapping relationship between java objects and relational database records, which is called ORM (that is, Object RelationMapping). People can achieve this function by encapsulating JDBC code. The packaged product is called ORM framework, and Hibernate is one of the popular ORM frameworks. Using the Hibernate framework, you can save an object to a relational database without writing JDBC code, simply calling a save method, and simply calling 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, you first configure the hibernate.cfg.xml file, which configures the database connection information, dialect, and so on, and also configures the corresponding hbm.xml file for each entity, and each hbm.xml file needs to be registered in the hibernate.cfg.xml file.
6. When applying Hibernate, it is important to understand the caching principle of Session, cascading, deferred loading and hql query.
(above, you can also combine your own tedious feelings about using JDBC to talk about hibernate.)
73, talk about your understanding of Spring.
1.Spring is a factory class that implements the factory pattern (here it is necessary to explain what the factory pattern is), which is called BeanFactory (actually an interface), and is usually a subclass of BeanFactory in the program, ApplicationContext. Spring is the equivalent of a large factory class that configures the class name and properties of the instance object through elements in its configuration file.
2. Spring provides good support for IOC. IOC is a programming idea and an architectural art, which can be used to decouple modules. IOC is also known as DI (Depency Injection).
3. Spring provides a good package of AOP technology. AOP is called aspect-oriented programming, which means that there are many methods of unrelated classes in the system. Among these methods, code of some system function should be added, such as adding logs, permissions judgment, and exception handling. This kind of application is called AOP.
The proxy technology is used to realize the AOP function, and the client program no longer calls the target, but invokes the proxy class. The proxy class and the target class have the same method declaration. There are two ways to achieve the same method declaration, one is to implement the same interface, and the other is to be a subclass of the target.
In JDK, Proxy classes generate dynamic proxies for an interface to generate implementation classes. If you want to generate subclasses for a class, you can use CGLI B. Add the system function and call the corresponding methods of the target class to the methods of the generated proxy class, and the proxy of the system function is provided by the Advice object. Obviously, in order to create the proxy object, at least the target class and the Advice class are needed. Spring provides this support, and you only need to configure these two elements in the spring configuration file to implement the proxy and aop functions.
(above, you can also talk about your views with your own experience.)
74, talk about the advantages and disadvantages of Struts
Advantages:
1. The implementation of MVC pattern, the structure is clear, so that developers only focus on the implementation of business logic.
2. There is a wealth of tag available, and Struts's tag library (Taglib) can be used flexibly, which can greatly improve the efficiency of development.
3. Page navigation makes the context of the system clearer. Through a configuration file, we can grasp the relationship between the various parts of the whole system, which is of great benefit to the later maintenance. This advantage is even more obvious when another group of developers take over the project.
4. Provide Exception processing mechanism.
5. Database link pool management
6. Support for i18n
Disadvantages:
First, when you go to the display layer, you need to configure forward. If you have ten display layers of jsp, you need to configure struts ten times, not including sometimes directory and file changes, and you need to modify forward. Note: after each configuration change, you need to redeploy the entire project, and a server like tomcate must also restart the server.
Second, the Action of Struts must be in thread-safe mode, which allows only one instance to process all requests. Therefore, all the resources used by action must be synchronized, which leads to the problem of thread safety.
Third, the test is not convenient. Each Action of Struts is coupled to the Web layer, so its testing depends on the Web container, and unit testing is difficult to implement. However, there is a Junit extension tool Struts TestCase that can implement its unit testing.
Fourth, the conversion of types. Struts's FormBean treats all data as String types, which can be converted using the tool Commons-Beanutils. But its conversions are all at the Class level, and the type of conversion is not configurable. It is also very difficult for error messages during type conversion to be returned to the user.
Fifth, the dependence on Servlet is too strong. Struts must rely on ServletRequest and ServletResponse when dealing with Action, so it can't get rid of the Servlet container.
Sixth, the front-end expression language. Struts integrates JSTL, so it mainly uses JSTL expression language to obtain data. However, JSTL's expression language is weak in terms of Collection and index properties.
Seventh, it is difficult to control the implementation of Action. Struts creates an Action, and it will be very difficult to control the order in which it is executed. You even have to rewrite Servlet to meet your functional requirements.
Eighth, the pre-and post-processing of Action. Struts is based on class hierarchies when dealing with Action, so it is difficult to operate before and after action processing.
Ninth, there is not enough support for the incident. In struts, it is actually a form Form that corresponds to an Action class (or DispatchAction). In other words: in Struts, a form can only correspond to one event. The event mode of struts is called application event,application event, which is a coarse-grained event compared with component event.
What's the difference between Hibernate and iBatis?
The same point: block the underlying access details of jdbc api, so that we can access data without dealing with jdbc api.
Jdbc api programming process is fixed, but also the sql statements and java code mixed together, often need to piece together sql statements, the details are very tedious.
Benefits of ibatis: shielding the underlying access details of jdbc api; separating sql statements from java code; providing the function of automatically encapsulating the result set called entity objects and collections of objects, queryForList returning a collection of objects and returning a single object with queryForObject; providing parameters that automatically pass the attributes of entity objects to the sql statement.
Hibernate is a fully automatic orm mapping tool, it can automatically generate sql statements, ibatis requires us to write sql statements in the xml configuration file, hibernate is much more responsible and powerful than ibatis. Because hibernate automatically generates sql statements, we can't control the statement, so we can't write specific efficient sql. For some less complex sql queries, hibernate can help us complete very well, but for particularly complex queries, hibernate is very difficult to adapt, this time using ibatis is a good choice, because we still write our own sql statements for ibatis.
76. How many fields are taken from each table in the multi-table query in hibernate, that is to say, how to solve the problem that the result set of the query does not have an entity class corresponding to it?
Solution 1: extract the data according to the Object [] data, and then group your own bean
Solution 2: write a constructor for the bean of each table. For example, if two field1,field2 fields are found in Table 1, then one constructor is Bean (type1filed1,type2).
Field2), and then the bean can be generated directly in hql.
77, introduce the secondary cache of Hibernate
Answer according to the following ideas:
(1) first of all, make clear what is caching.
(2) Session with hibernate is the first-level cache, that is, if there is a first-level cache, why is there a second-level cache?
(3) finally, we will talk about how to configure the secondary cache of Hibernate.
1, caching is to store previously queried and used objects from the database in memory (in a data structure), this data structure is usually or similar to HashMap, when you want to use an object in the future, first query whether there is an object in the cache, if so, use the object in the cache, if not, query the database, and save the queried object in the cache for next use.
2 Session of Hibernate hibernate is a kind of cache, which we usually call the first-level cache of Hibernate. When you want to use session to query an object from the database, Session will first check whether there is an object from within it, and then return directly if it exists, and then go to access the database without existence and save the query results inside itself.
Because Session represents a session, and a Session is associated with a database connection, it is best not to keep Session open for a long time, usually only in a transaction, and should be closed at the end of the transaction. And Session is not thread-safe, so it is easy to have problems when shared by multiple threads. Usually only the kind of cache in the global sense is the real cache application and has greater cache value. therefore, the caching effect of the Session cache of Hibernate is not obvious, and the application value is not great. The secondary cache of Hibernate is to configure a global cache for Hibernate so that multiple threads and transactions can share the cache. What we hope is that one person has used it, and others can also use it. Session does not have this effect.
3. Secondary cache is a software component independent of Hibernate and belongs to third-party products. Many manufacturers and organizations provide cache products, such as EHCache, OSCache and so on. To use secondary cache in Hibernate, you must first configure which manufacturer's cache product is used in the hibernate.cfg.xml configuration file, then configure the cache product's own configuration file, and finally configure which entity objects in Hibernate should be included in the management of secondary cache. After understanding the principle of secondary cache and having this idea, it is easy to configure the secondary cache of Hibernate.
Extended knowledge: a SessionFactory can be associated with a secondary cache, that is, a secondary cache can only cache data in a database. When using Hibernate's secondary cache, be careful not to have other applications or SessionFactory to change the data in the current database, so that the cached data will be inconsistent with the actual data in the database.
What is 78D JDO?
JDO is a new specification for Java object persistence, which is short for java data object. It is also a standardized API for accessing objects in a data warehouse. JDO provides transparent object storage, so for developers, storing data objects requires no additional code at all (such as the use of JDBC API). These tedious routines have been transferred to JDO product providers, freeing developers to focus on business logic. In addition, JDO is flexible because it can run on any data underlying layer.
Comparison: JDBC is only oriented to relational database (RDBMS) JDO is more general, providing any underlying data storage functions, such as relational database, file, XML and object database (ODBMS), etc., making the application more portable.
What is the difference between one-to-many and many-to-one two-way association of 79 ~ (th) hibernate?
The basic principles of one-to-many association mapping and many-to-one association mapping are the same, that is, a foreign key is added to one end of the many, and the main difference is that the maintenance end is different.
The difference lies in the relationship they maintain:
One-to-many association mapping refers to loading data of one end while loading data of one end. Many-to-one association mapping refers to loading data of one end while loading data of one end.
How does 80th hibernate delay loading?
1. Hibernate2 delay loading implementation: a) entity objects b) collections (Collection)
2. Hibernate3 provides the delayed loading function of attributes when Hibernate is querying data, the data does not exist in memory, when the program really operates on the data, the object exists in memory, which realizes delayed loading, which saves the memory overhead of the server, thus improving the performance of the server.
At this point, I believe you have a deeper understanding of "what framework interview questions do Java have". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
This thing is so powerful, www.spirent.com network equipment stress test.
© 2024 shulou.com SLNews company. All rights reserved.