"Java seconds technology seconds kill interviewer" common face question (four)

Source: Internet
Author: User
Tags aop set set

What are the main methods of 46.Request objects?

A: (1) setAttribute (String name,object): Sets the parameter value of the request named name

(2) getattribute (String name): Returns the property value specified by name

(3) Getattributenames (): Returns a collection of names of all properties of the request object, resulting in an instance of an enumeration

(4) GetCookies (): Returns all cookie objects of the client, resulting in an array of cookies

(5) getcharacterencoding (): Returns the character encoding in the request

(6) Getcontentlength (): Returns the length of the requested body

(7) GetHeader (String name): Gets the file header information defined by the HTTP protocol

(8) Getheaders (String name): Returns all values of the request header for the specified name, resulting in an instance of an enumeration

(9) Getheadernames (): Returns the name of the request header, the result is an instance of the enumeration

() getInputStream (): Returns the requested input stream for obtaining the data in the request

(one) GetMethod (): Obtaining a client's way of transmitting data to the server side

GetParameter (String name): Gets the parameter value specified by the client that is passed to the server side by name

(+) Getparameternames (): Gets the name of all parameters that the client sends to the server side, and the result is an instance of the enumeration

Getparametervalues (String name): Gets all values that have the parameter specified by name

(Getprotocol): Gets the name of the protocol on which the client transmits data to the server side

(+) getquerystring (): Get query string

(+) Getrequesturi (): Gets the client address that issued the request string

(+) getremoteaddr (): Gets the IP address of the client

(+) Getremotehost (): Gets the name of the client

() getsession ([Boolean create]): Returns and requests the relevant session

(+) getServerName (): Gets the name of the server

Getservletpath (): Gets the path of the script file requested by the client

(at) Getserverport (): Gets the port number of the server

RemoveAttribute (String name): Delete One of the properties in the request

47. Talk about your understanding of struts?

A: ①struts is a web-layer framework designed by MVC pattern, which is actually a large servlet called action

Servlet, or subclass of Actionservlet. We can hand over all requests conforming to a feature in the Web,xml file to the servlet, and the servlet references the file (the length is/web-inf/ Struts.cfg.xml) Each request is assigned to a different action to handle; (an extension of knowledge: Struts can have multiple profiles that can be configured according to the module, which prevents the transition of the configuration file from expanding)

②actionservlet the argument to a Formbean object (which is a Java class in which each property in the class corresponds to a request parameter) is encapsulated into a Formbean object before the request is handed over to the action. Look at the configuration file.

③ to illustrate, Actionservlet may call Formbean's Validate method for validation before passing the Formbean object to the action's Execute method, only after the checksum is passed. The Formbean object is passed to the action's Execute method, otherwise it will return an error page with the input property specified, (see configuration file) Why did the author name This here the input property instead of the error attribute?

④action after execution, to return to the result view, this result view is represented by a Actionforward object, The Actionforward object is associated to a JSP page by 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 enables the action program code to be implemented with the returned JSP page Decoupling of the face name.

48 Talk about your understanding of hibernate?

A: ① Overview: It is an ORM (object-relational mapping) framework for persistent layers, using the hibernate framework, instead of writing JDBC code, simply invoking a save method, you can save the object to a relational database; Just call a Get method, You can load an object from the database.

② uses Hibernate's basic process: Configuring Configuration objects, generating Sessionfactory, creating session objects, opening transactions, completing CRUD operations, committing transactions, and closing sessions.

③ configuration file: When using Hibernate, configure the Hibernate.cfg.xml file first. It configures the data connection information and dialect, and also configures the corresponding Hbm.xml file for each entity, and then introduces it in the Hibernate.cfg.xml file;

④ Relational Mappings:

A) one-to-many:

(Ⅰ) party: You need to add a set set containing multiple parties, note that you must be new.

(Ⅱ) Multi-party: Add the Bean object of one side, note not new.

(Ⅲ) Note: Only one side can be configured for normal maintenance operation. The general party will abandon the foreign key maintenance.

b) Many-to-many: many-to-many saves, one party must abandon maintenance of the intermediate table "Inverse=ture"

⑤ Cascade Relationship: 6 Kinds of Cascade value

none--do not use cascading

save-update--Save or modify

delete--Delete

delete-orphan--Orphan Delete (only a couple more!) )

all--except orphans removed, all the other

all-delte-orphan--contains orphans to remove all.

⑥ Lazy Loading:

Bottom: Dynamic Agent technology

====> to query ID value at first query, generate proxy object (ID only)

     =====> 继续操作,如打印某属性  ==发送sql语句==> 返回查询值

Class-Level lazy loading: querying for an object

Session.get () do not delay loading

Session.load () Lazy Loading

Difference between the two

Deferred loading at the association level

 fetch="select" lazy="true"  延迟加载(默认) fetch="select" lazy="false" 不延迟加载 fetch="select" lazy="extra" 极其延迟加载

⑦hibernate three kinds of retrieval methods:

QBC (Query by Criteria)

HQL (Hibernate Query Language)

SQL (Basic No)

⑧ Cache:

Caching Concepts

 缓存是内存中开辟的一块空间,用来保存数据 实质是:一些集合设计

First Level cache: Session

    自带的,不能卸载。一定存在的,与Session生命周期一样长

Second-level cache:

    默认没有开启,只提供了相关的策略,需第三方插件,常用EHCache。

Snapshot mechanism (SnapShot)

    持久态对象,在获取的时候,会保存两份:一份在缓存区,一份在快照区;    在事务提交之前,会自动对比缓存区和快照区的数据,    如果不一致,会自动修改缓存和快照区数据;

49. Talk about your understanding of spring?

①spring is an open source business layer Framework, sub-module, one-stop framework, which integrates various other mainstream frameworks;

The essence of ②spring is a factory class that implements the factory pattern, in which the instance object is created by adding tags in its configuration file;

③spring's core--ioc/di;

A) the IoC (inverse of control) controls the reversal, giving the creation of the object to spring to manage, and then spring is easily injected into the caller through a dependency injection. The advantage of this is that the bean and the bean are organized together in the form of a configuration file, rather than being coupled in a hard-coded fashion.

b) There are three ways of dependency injection: interface injection, setter method injection (use), and structure injection;

c) The IOC's annotated approach:

(Ⅰ) Turn on component scanning in the Applicationcontext.xml configuration file

(Ⅱ) Adding annotations on the Implementation class: @Component (value= "id value")

Three derivative annotations of the @Component (same function)

    • @Controller--acting on the web layer

    • @Service-acting on the business layer

    • @Repository--acting on the persistence layer

(Ⅲ) 3. Annotation of attribute injection (note: The use of annotation injection, can not provide a set method)

    • @Value--for injecting common types

    • @Autowired--Automatic assembly by type by default

    • @Qualifier--forcing the use of name injection

    • @Resource-equivalent to @autowired and @qualifier, emphasizing: Java-provided annotations, properties using the Name property

④spring's core--AOP;

A) AOP (aspect-oriented programming), can not modify the source code under the premise of the program to enhance, for example, join the log, add permission to judge, add exception processing, etc.

b) The underlying AOP uses agent technology, which is divided into JDK dynamic agent (interface oriented) and Cglib dynamic agent (no interface, generation of sub-class proxy);

c) Steps to use:

(Ⅰ) write the Slice class ==> Configure the bean label for the Slice class in the IOC ==> configure AOP-related

(Ⅱ) pointcut expression: Execution ([modifier] Returns a value type package name. Class Name. Method name (parameter))

The general shorthand is: Execution ( com). . daoimpl.save* (..))

(Ⅲ) Notification type

Pre-notification:

Final notification: If the program has an exception, the final notification will also be executed.

Post notification:

Exception Throw Notification:

Surround Notifications:

    • Note: The target's method is not executed by default and requires the Proceedingjoinpoint pair to be used by the target object's method for execution.

What is the difference between 50.JDBC, Ibatis (MyBatis), and hibernate?

A: ①JDBC programming process fixed, while the SQL statement and Java code mixed together, often need to piece together SQL statements, details are cumbersome;

②ibatis (MyBatis) It's not exactly an ORM framework, because MyBatis requires programmers to write their own SQL statements, but mybatis can flexibly configure SQL statements to run with XML or annotations. The Java object and the SQL statement map are generated to the final executed SQL, and the result of SQL execution is then mapped to the Java object. However, MyBatis can not do database independence, if you need to implement software that supports a variety of databases, you need to customize multiple sets of SQL mapping files, a lot of work.

③hibernate object/Relational mapping ability, database independence is good, because hibernate automatically generate SQL statements, we cannot control the statement, we can not 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.

"Java seconds technology seconds kill interviewer" common face question (four)

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.