81. How does the transaction work in JDBC?
A: Connection provides a method of transaction processing by calling Setautocommit (false) to set up a manual commit transaction, committing the transaction explicitly with commit () when the transaction is complete, or by rollback () If an exception occurs during transaction processing The transaction is rolled back. In addition to this, the concept of savepoint (SavePoint) has been introduced from JDBC 3.0, allowing you to set the SavePoint through code and roll the transaction back to the specified savepoint.
82. Can JDBC handle blobs and CLOB?
A: BLOBs refer to Binary Large objects (binary Large object), while Clob is a big character object (Character Large objec), where BLOBs are designed to store large binary data. The CLOB is designed to store large text data. Both the PreparedStatement and resultset of JDBC provide the appropriate methods to support BLOB and CLOB operations.
83, a brief description of the regular expression and its use.
A: When writing a program that handles strings, there is often a need to find strings that match certain complex rules. Regular expressions are the tools used to describe these rules. In other words, the regular expression is the code that records the text rule.
Description: The information that was processed at the beginning of the birth of the computer is almost always numeric, but times have changed, today we use computers to process information more often than numeric values but strings, regular expressions are the most powerful tool for string matching and processing, and most languages provide support for regular expressions.
84. How is the regular expression operation supported in Java?
A: The string class in Java provides methods to support regular expression operations, including: Matches (), ReplaceAll (), Replacefirst (), Split (). In addition, you can use the pattern class to represent regular expression objects in Java, which provides a rich API for various regular expression operations.
Interview question:-If you want to intercept the string from the first opening parenthesis, for example: Beijing (Chaoyang District) (Xicheng area) (Haidian), the result of interception is: Beijing, then the regular expression how to write?
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class RegExpTest {
public static void main (String [] args) {
String str = "Beijing (Chaoyang District) (Xicheng District) (Haidian District)";
Pattern p = Pattern.compile (". *? (? = \\ ()");
Matcher m = p.matcher (str);
if (m.find ()) {
System.out.println (m.group ());
}
}
}
85. What are the ways to get class objects of a class?
For:
- Method 1: Type. Class, for example: String.class
- Method 2: Object. GetClass (), for example: "Hello". GetClass ()
- Method 3:class.forname (), for example: Class.forName ("java.lang.String").
86. How can I create an object from reflection?
For:
- Method 1: Call the Newinstance () method through the class object, for example: String.class.newInstance ()
- Method 2: Use the GetConstructor () or Getdeclaredconstructor () method of the class object to get the constructor (Constructor) object and call its newinstance () method to create the object. For example: String.class.getConstructor (String.class). newinstance ("Hello");
87, how to get and set the value of the object private field through reflection?
A: You can use the Getdeclaredfield () Method Field object of the class object, and then set it to be accessible through the Field object's Setaccessible (true), and then you can get/set the value of the field by Get/set method.
89, briefly describe the object-oriented "six principles of law."
For:
- single Duty principle: A class does only what it should do. (single duty principle wants to express is "high cohesion", write code Ultimate principle only six words "high cohesion, low coupling".
- Opening and closing principle: software entities should be open to extensions and closed for modification. (In an ideal state, when we need to add new functionality to a software system, we just need to derive some new classes from the original system, without having to modify any of the original lines of code.) To open and close there are two points: ① abstraction is the key, if there is no abstract class or interface system in a system without an extension point, ② package variability, the system of various variables encapsulated in an inheritance structure, if a number of variables mixed together, the system will become complex and chaotic, if not clear how to encapsulate the variability, You can refer to the chapter on bridge mode in the "Design pattern Refinement" book. )
- Dependency reversal principle: interface-oriented programming. (This principle is straightforward and concrete is that when declaring a method's parameter type, the return type of the method, the reference type of the variable, use the abstract type as much as possible instead of the concrete type, because the abstract type can be replaced by any one of its subtypes, refer to the following Richter substitution principle.) )
- Richter Replacement Principle: The parent type can be replaced at any time by a subtype. (For the description of the Richter replacement principle, Ms Barbara Liskov's description is much more complicated than this, but it is simply that the subtype can be used where the parent type is used.) The Richter substitution principle can check whether the inheritance relationship is reasonable, if an inheritance relationship violates the Richter scale substitution principle, then the inheritance relationship must be wrong and the code needs to be refactored. For example, letting a cat inherit a dog, or a dog inheriting a cat, or letting a square inherit a rectangle is a false inheritance, because you can easily find a scenario that violates the Richter scale substitution principle. It is important to note that subclasses must be able to increase the ability of the parent class rather than reduce the ability of the parent class, because the child is more capable of analogy with the parent, and the ability to use a lot of objects as a less capable object is certainly not a problem. )
- interface Isolation principle: The interface should be small and dedicated, must not be chatty. (bloated interface is the pollution of the interface, since the interface represents the ability, then an interface should only describe a capability, the interface should also be highly cohesive.) For example, four arts should be designed as four interfaces, and should not be designed as an interface of four methods, because if designed as an interface in four methods, then this interface is very difficult to use, after all, four arts four is proficient in a few people, and if designed to four interfaces, will implement several interfaces, In this way, the likelihood that each interface is reused is very high. The interface in Java represents the ability, the representative Convention, the representative role, the correct use of the interface must be an important indicator of the level of programming. )
- Synthetic Aggregation Reuse principle: takes precedence over the use of aggregation or composition-relationship reuse code. (Through inheritance, the use of code is the object-oriented programming of the most abused things, because all textbooks are not an exception to the inheritance has been advocated to mislead the beginner, class and class between the simple say there are three relations, is-a relationship, has-a relationship, use-a relationship, respectively, representing the inheritance, Associations and dependencies. Among them, the association relationship according to its associated strength can be further divided into association, aggregation and synthesis, but plainly all are has-a relations, the synthetic polymerization principle is to express the priority to consider the has-a relationship rather than is-a relationship reuse code, reason why you can find 10,000 reasons from Baidu, need to explain is , even in the Java API there are many examples of abuse of inheritance, such as the properties class inherits the Hashtable class, the stack class inherits the vector class, these inheritance is obviously wrong, A better practice is to place a member of the Hashtable type in the Properties class and set its key and value to a string to store the data, and the stack class should also be designed to place a vector object in the Stack class to store the data. Remember: Do not inherit tool classes at any time, and tools can be owned and used instead of inherited. )
- Dimitri Law: The Dimitri rule is also called the least knowledge principle, and an object should have as little understanding of other objects as possible. (Dimitri Law is simply how to do "low coupling", the façade mode and the mediator mode is the practice of the Dimitri Law.) For the façade mode can give a simple example, you go to a company to negotiate business, you do not need to understand how the company's internal operation, you can even know nothing about the company, go to the company at the entrance only need to find the front desk beauty, tell them what you want to do, they will find the right person to contact you, The beauty at the front desk is the façade of the company's system. Complex systems can provide users with a simple façade, Java web development as a front-end controller servlet or filter is not a façade, the browser does not know how to operate the server, but through the front-end controller can be based on your request to get the corresponding service. The mediator model can also give a simple example to illustrate, such as a computer, CPU, memory, hard disk, graphics card, sound card various devices need to cooperate to work well, but if these things are directly connected together, the computer cabling will be unusually complex, in this case, The motherboard appears as a mediator, connecting the devices together without needing to exchange data directly between each device, thus reducing the coupling and complexity of the system.
90, briefly describe the design patterns you know.
A: the so-called design pattern is a summary of the repeated use of code design experience (a proven solution to a problem in the context). The uses design patterns for reusable code, making code easier for others to understand, and ensuring code reliability. Design patterns make it easier and easier to reuse successful designs and architectures. The presentation of proven technologies into design patterns will also make it easier for new system developers to understand their design ideas. The
in Gof's Design patterns:elements of reusable object-oriented software gives class three (the creation [abstraction of the instantiation of a class], the structural type [ Describes how to combine a class or object to form a larger structure], behavior [to divide responsibility between different objects and abstract the algorithm]) 23 design patterns, including: abstract Factory (Abstraction Factory mode), builder (Builders mode), Factory Method (Factory mode), Prototype (original model mode), Singleton (singleton mode), facade (façade mode), Adapter (adapter mode), Bridge (bridge mode), Composite (compositing mode), Decorator (decorative mode), Flyweight (enjoy meta mode), Proxy (Command mode), interpreter (interpreter mode), Visitor (visitor mode), Iterator (iterative sub-mode), Mediator (mediator mode), Memento (Memo mode), OBSERVER (Observer mode), State (status mode), strategy (policy mode), template method (templated methods mode), Chain of Responsibility (responsibility chain mode).
When asked about design patterns, you can pick the most common answers, such as:
- Factory mode: Factory classes can generate different instances of subclasses based on conditions, which have a common abstract parent class and implement the same method, but these methods operate differently for different data (polymorphic methods). When an instance of a subclass is obtained, the developer can call a method in the base class without having to consider which instance of the subclass is returned.
- Proxy Mode: provides a proxy object for an object and controls the reference of the original object by the proxy object. In actual development, according to the different purposes, the agent can be divided into: Remote agent, virtual agent, protection agent, cache agent, firewall agent, synchronous agent, intelligent reference Agent.
- Adapter Mode: transforms the interface of a class into another interface that the client expects, so that classes that are not used together because of an interface mismatch can work together.
- Template Method Pattern: Provides an abstract class that implements partial logic in the form of a concrete method or constructor, and then declares some abstract methods to force subclasses to implement the remaining logic. Different subclasses can implement these abstract methods in different ways (polymorphic implementations), thus implementing different business logic.
In addition, can also talk about the above mentioned façade mode, bridge mode, single case mode, decorating mode (collections tools and I/O system are used in decorating mode), anyway, the basic principle is to pick their most familiar, use the most answers, lest throat.
92. What is UML?
A: UML is the abbreviation for the Unified Modeling Language (Unified Modeling Language), which was published in 1997, which synthesized the object-oriented modeling language, methods and processes that existed at that time, and is a graphical language that supports modeling and software system development. Provides modeling and visualization support for all phases of software development. Using UML can help communicate and communicate, facilitate application design and document generation, and explain the structure and behavior of the system.
93. What are the common diagrams in UML?
A: UML defines a number of graphical symbols to describe a part or all of the static and dynamic structure of a software system, including: Use cases Diagram, Class diagrams (classes diagram), time series diagrams (sequence diagram), Collaboration diagrams (collaboration diagram), State diagrams (statechart diagram), activity diagrams (Activities diagram), component diagrams (component diagram), Deployment diagrams (Deployment diagram) and so on. Of these graphical symbols, there are three of the most important, namely: Use case diagram (to capture requirements, describe the function of the system, through which you can quickly understand the system's functional modules and their relationships), class diagram (describing the class and the relationship between classes and classes, through which you can quickly understand the system), Time series diagrams, which describe the interaction between objects and the order in which they are executed, through which you can see what messages an object can receive, that is, the services the object can provide to the outside world.
94. What is ORM?
A: Object-relational mapping (object-relational Mapping, or ORM) is a technique to solve the mismatch between the object-oriented model of the program and the relational model of the database. Simply put, ORM is to automatically persist objects in a Java program to a relational database or to convert rows from a relational database table to a Java object by using metadata that describes the mapping between the object and the database (either XML or annotations), essentially converting the data from one form to another.
95, say your understanding of the agreement better than the configuration (CoC).
A: The convention is better than configuration (Convention over config), also known as convention programming, is a software design paradigm designed to reduce the number of decisions that software developers need to make, and to gain simple benefits without sacrificing flexibility. The COC essence is that developers only need to specify the part of the application that does not conform to the agreement. For example, if you have a class named sale in your model, the corresponding table in the database is named Sales by default. Only when you deviate from this convention, for example by naming the table Products_sold, do you want to write a configuration about that name. If the conventions of the tools you use are consistent with what you expect, you can save the configuration and, conversely, you can configure them to achieve the way you expect them to. Following the Convention although the loss of a certain degree of flexibility, can not arbitrarily arrange the directory structure, can not be arbitrary function naming, but can reduce the configuration. More importantly, adherence to conventions can help developers comply with building standards, including various named specifications, which is advantageous for team development.
96. Speak the life cycle of the servlet
A: After the Web container loads the servlet and instantiates it, the servlet life cycle begins, the container runs its init () method for the servlet initialization, and the service method of the servlet is called when the request arrives. The service method calls the Doget or dopost corresponding to the request, and when the server shuts down, the server destroys the servlet instance when the project is unloaded, and the servlet's Destroy method is called.
The Servlet interface defines 5 methods, of which the first three are related to the servlet life cycle:
- 1.void init (servletconfig config) throws Servletexception
- 2.void Service (ServletRequest req, Servletresponse resp) throws--Servletexception, java.io.IOException
- 3.void Destory ()
- 4.java.lang.string Getservletinfo ()
- 5.ServletConfig Getservletconfig ()
97. What is the difference between forwarding (forward) and redirection (redirect)?
A: Forward is the control of the container in the steering, is the server request resources, the server directly access the URL of the destination address, the URL of the response to read the content, and then send the content to the browser, the browser does not know where the server sent the content from where, So its address bar is still the original address. Redirect is the server-side logic, send a status code (302), tell the browser to request the address again, so from the browser's address bar can see the link address after the jump. The former is more efficient, when the former can meet the needs, as far as possible using forwarding (through the RequestDispatcher object of the Forward method, The RequestDispatcher object can be obtained through the Getrequestdispatcher method of the ServletRequest object, and it also helps to hide the actual link, in some cases, for example, to jump to a resource on a different server. You must use a redirect (call its Sendredirect method through the HttpServletResponse object).
98. What are the built-in objects of JSP? What are the roles?
A: JSP has 9 built-in objects:
-1.request: Encapsulates the client's request, which contains parameters from a Get or POST request;
-2.response: Encapsulates the response of the server to the client;
-3.pageContext: Other objects can be obtained through this object;
-4.session: Encapsulates the user session object;
-5.application: Encapsulates the object of the server running environment;
-6.out: The output stream object of the output server response;
-Configuration object for 7.config:web application;
-8.page:jsp the page itself (equivalent to this in a Java program);
-9.exception: Encapsulates an object that throws an exception on the page.
"Supplemental" If you use a servlet to generate dynamic content in a Web page is undoubtedly a tedious task, on the other hand, all text and HTML tags are hard-coded, and even minor changes need to be recompiled. The JSP solves these problems with the servlet, which is a good addition to the servlet that can be used exclusively as a view for rendering to the user, and the servlet acts as a controller that handles user requests and forwards or redirects to a page. Many of the Java-based Web development uses both Servlets and JSPs. The JSP page is actually a servlet, the server that can run the servlet (servlet container) is usually a JSP container, can provide the environment of JSP page, Tomcat is a servlet/jsp container. The first time a JSP page is requested, the servlet/jsp container first translates the JSP page into a JSP page implementation class, which is a Java class that implements the Jsppage interface or its sub-interface httpjsppage. The Jsppage interface is a sub-interface of the servlet, so each JSP page is a servlet. After the conversion succeeds, the container compiles the servlet class, then the container loads and instantiates the Java bytecode and executes the life-cycle operations it typically does with the servlet. For subsequent requests to the same JSP page, the container will see if the JSP page has been modified and will be re-converted and recompiled and executed if modified. If not, the servlet instance that already exists in memory is executed.
99. What are the differences between get and post requests?
For:
- ①get requests are used to obtain resources from the server, and post is used to submit data to the server;
- ②get adds the data in the form to the URL that the action points to by Name=value, and uses "?" for both. Connection, and the use of "&" between variables, post is to put the data in the form in the HTML header (header), passed to the URL that the action points to;
- ③get data transmitted by the URL length limit (1024 bytes), and post can transfer a large amount of data, upload files can only use post mode;
- ④ parameters are displayed on the address bar when using GET, you can use get if the data is not sensitive, or use post for sensitive data or applications;
- ⑤get uses the format of the MIME type application/x-www-form-urlencoded URL encoding (URL encoding, also called percent-coded) text to pass parameters to ensure that the transmitted parameters are composed of the text that follows the specification, For example, the encoding of a space is "%20".
100. What is the relationship between JSP and servlet?
A: The servlet is a special Java program that runs in the server's JVM and can rely on the server's support to provide the viewer with the display content. JSP is essentially a simple form of a servlet, and JSP is processed by the server into a servlet-like Java program that simplifies the generation of page content. The main difference between Servlets and JSPs is that the application logic of the servlet is in the Java file and is completely detached from the HTML in the presentation layer. The case of JSP is that Java and HTML can be combined into a file with a. jsp extension (some say, the servlet is in Java to write HTML, and JSP is in the HTML to write Java code, of course, this statement is very one-sided). The JSP focuses on the view, and the servlet focuses more on the control logic, in the MVC schema pattern, the JSP is suitable to act as a view and the servlet is suitable to act as a controller.
101, four kinds of scopes in JSP?
Answer: page, request, session, and application, as follows:
- ①page represents the objects and properties associated with a page.
- ②request represents the objects and properties associated with a request made by a Web client. A request may span multiple pages, involve multiple Web components, and temporary data that needs to be displayed on the page can be placed in this scope
- ③session represents the objects and properties associated with a session that a user has established with the server. Data related to a user should be placed in the user's own session
- ④application represents objects and properties related to the entire Web application, which is essentially a global scope that spans the entire Web application, including multiple pages, requests, and sessions.
102. What are the techniques for implementing session tracking?
A: Because the HTTP protocol itself is stateless, the server in order to distinguish between different users, you need to track the user session, simply to register for the user, assign a unique ID to the user, the next time the user contains this ID in the request, the server to determine exactly which user.
-
- ①url rewrite: Adds the user session's information to the URL as a parameter of the request, or adds a unique session ID to the end of the URL to identify a session.
-
- ② set a form hidden field: Adds a field that is associated with a session trace to an implicit form field that is not displayed in the browser but is submitted to the server when the form is submitted.
These two ways are difficult to handle information passing across multiple pages, because if you modify the URL every time or add an implicit form field to the page to store information about the user's session, things can become cumbersome.
-
- There are two kinds of ③cookie:cookie, one is window-based, the browser window is closed, the cookie is gone, the other is storing the information in a temporary file, and setting the time of existence. When a user establishes a session through a browser and server, the session ID is stored in a window-based cookie with the response information, which means that the session is not timed out as long as the browser is not closed, and the session ID is submitted to the server for the server to identify the user on the next request. You can save information for a user in a session. The session object is in server memory, and the window-based cookie is in client memory. If the browser disables cookies, then there are two ways to track the session. Of course, there are a few things to keep in mind when using cookies: first do not store sensitive information in cookies; second, the amount of data stored in cookies is limited (4k), and you cannot store too much content in cookies; Moreover, browsers usually allow up to 20 cookies for a single site. Of course, other information related to user sessions (in addition to the session ID) can also be present with cookies for easy session tracking.
-
- ④httpsession: In all session tracking techniques, the HttpSession object is the most powerful and most versatile. When a user accesses a site for the first time, HttpSession is created automatically, and each user can access his or her own httpsession. HttpSession can be obtained through the GetSession method of the HttpServletRequest object, and a value can be placed in setattribute by HttpSession HttpSession method. By calling the GetAttribute method of the HttpSession object and passing in the property name, you can get the object that is saved in HttpSession. Unlike the above three ways, HttpSession is placed in the server's memory, so do not put oversized objects inside, even though the current servlet container can move objects from httpsession to other storage devices when the memory is full, but this will inevitably affect performance. The value added to the httpsession can be any Java object, and it is best to implement the serializable interface so that the servlet container can serialize it to a file when necessary, or an exception will occur when serializing.
103. What are the functions and usages of filters?
A: Filters (filter) in Java Web development are features that are added from the servlet 2.3 specification and are enhanced in the Servlet 2.4 specification. For Web applications, a filter is a server-resident Web component that intercepts request and response information between the client and the server and filters the information. When a Web container receives a request for a resource, it will determine if there is a filter associated with the resource. If so, the container will give the request to the filter for processing. In the filter, you can change the content of the request, or reset the requested header information, and then send the request to the target resource. When the target resource responds to the request, the container also forwards the response to the filter, and then the filter, you can convert the contents of the response, and then send the response to the client.
Common filter uses include: Unified authentication of user requests, record and audit user's access requests, filter or replace data sent by users, convert image format, compress response content to reduce transmission, add and decrypt requests or responses, trigger resource access events, Apply XSLT to the output of XML, and so on.
Filter-related interfaces include: Filter, Filterconfig, Filterchain
104. What are the functions and usage of listeners?
A: The Listener in Java Web development (listener) is a functional component that application, session, request three objects are created, destroyed, or automatically executed when the Delete property is modified, as follows:
- ①servletcontextlistener: Listens for the creation and destruction of servlet contexts.
- ②servletcontextattributelistener: Listens for the addition, deletion, and substitution of servlet context properties.
- ③httpsessionlistener: Listen for the session creation and destruction.
Add: There are two cases of Session destruction: 1, Session timeout (can be configured in Web. XML via/Tag timeout), 2, by calling the Session object's invalidate () method to invalidate the session.
- ④httpsessionattributelistener: Listens for the addition, deletion, and substitution of attributes in the session object.
- ⑤servletrequestlistener: The initialization and destruction of the request object is monitored.
- ⑥servletrequestattributelistener: Listens for the addition, deletion, and substitution of request object properties.
105. What is the role of Web. xml?
A: Information about configuring Web apps such as: Listeners (listener), filters, Servlets, related parameters, session time-outs, security authentication methods, error pages, and so on. For example:
106. What Jstl tags are used in your project?
A: The main use of Jstl's core tag library, including 、、、、, is mainly used to construct loops and branching structures to control display logic.
"description" Although the JSTL tag library provides a library of tags such as core, SQL, FMT, and XML, it is recommended to use only the core tag libraries (cores) in real-world development, and it is best to use only branching and looping tags, supplemented by expression language (EL), to truly decouple data display and business logic, This is the best practice.
107. What are the benefits of using the tag library? How do I customize my JSP tags?
A: The benefits of using a tag library include the following:
- 1. Separate the content and logic of JSP pages, simplifying web development;
- 2. Developers can create custom tags to encapsulate business logic and display logic;
- 3. The label has good portability, maintainability and reusability;
- 4. Avoid the use of scriptlet (a lot of company project development is not allowed to write in JSP)
The custom JSP tags include the following steps:
- 1. Write a Java class implementation implementation Tag/bodytag/iterationtag interface (typically not directly implemented-these interfaces instead inherit the Tagsupport/bodytagsupport/simpletagsupport class, This is the application of the default adaptation mode in adapter mode)
- 2. Rewrite doStartTag (), Doendtag () and other methods to define the function of the label to complete
- 3. Write a label description file with a TLD extension to deploy the custom label, and the TLD file is usually placed in the Web-inf folder or its subdirectories
- 4. Use the TAGLIB directive in the JSP page to reference the tag library.
108. The implicit object of expression language (EL) and its function?
A: PageContext, Initparam (Access context parameter), param (Access request parameters), Paramvalues, header (Access request header), Headervalues, cookie (Access cookie), Applicationscope (Access Application scope), Sessionscope (Access session scope), Requestscope (Access request scope), Pagescope (Access page scope). The usage is as follows:
${pageContext.request.method}${pageContext["request"]["method"]}${pageContext.request["method"]}${pageContext["request"].method}${initParam.defaultEncoding}${header["accept-language"]}${headerValues["accept-language"][0]}${cookie.jsessionid.value}${sessionScope.loginUser.username}
The. and [] operations of the "supplemental" expression language are consistent, the only difference being that if the property name being accessed does not match the Java Identifier naming convention, for example, the accept-language above is not a valid Java identifier, then only the [] Operator and cannot be used. Gets the value of it.
109. What operators are supported by the expression language (EL)?
Answer: In addition to the. and [] operators, El also provides:
- ? Arithmetic operators: + 、-、 *,/or div,% or mod
- ? relational operators: = = or EQ,! = or NE, > or GT, >= or GE, < or LT, <=, or Le
- ? logical operator:&& OR and, | | Or,!, or not
- ? conditional operator: ${statement? A:B} (similar to the Java conditional operator)
- ? Empty operator: Checks whether a value is null or empty (array length is 0 or no element in the collection returns True)
110. Please explain the following nouns in Java EE
For:
-
- 1. Container: The container provides run-time support for Java EE application components. The container provides a federated view from the underlying Java EE API to the application components. Java EE application components cannot directly interact with other Java EE application components. They achieve the interaction between them and their platform services through the container's protocols and methods. Inserts a container between the application component and the Java EE Service, which allows the container to transparently inject necessary services for the component, such as declarative transaction management, security checks, resource pooling, and state management.
-
- 2. Resource adapter: A resource adapter is a system-level component that typically implements a network connection to an external resource manager. Resource adapters can extend the functionality of the Java EE platform. This only requires implementing a Java EE standard service API (such as a JDBC driver), or defining and implementing a resource adapter that can be connected to an external application system. The resource adapter can also provide full local or local resources for the service. The resource adapter interface connects to the Java EE platform through the Java EE Service Provider Interface (Java EE SPI). Resource adapters that connect to the Java EE platform using the Java EE SPI can work with all Java EE products.
-
- 3.JNDI (Java Naming & directory Interface): Java named Directory interface, the main function is to provide a directory system, so that other applications in the other places to leave their own index, This allows you to quickly find and locate distributed applications.
-
- 4.JMS (Java Message Service): The Java Messaging services are standard APIs for message delivery and support reliable "point-to-point" messaging and "publish-subscribe" models. The Java EE specification requires that the JMS vendor implement both "point-to-point" messaging and "Publish/subscribe" message delivery.
-
- 5.JTA (Java Transaction API): Java transaction programming interface. The Java Transaction API consists of two parts: ① an application-level boundary interface, which is used by container and application components to divide transaction boundaries, and ② a Java EE SPI-level interface between the transaction manager and the resource manager.
-
- 6.JPA (Java Persistence API): The Java Persistence API is a standard API for persistence and object/relational mapping management. By using a Java domain model to manage relational databases, the Java EE specification provides an object/relational mapping capability for application developers. Java EE must provide support for the Java Persistence API. It can also be used in a Java SE environment.
-
- 7.JAF (JavaBean Activation framework): The JAF API provides a framework for handling data of different MIME types that originate in different formats and locations. The JavaMail API uses the JAF API. The JAF API is included in Java SE, so it can be used by Java EE applications.
-
- 8.JAAS (Java authentication and Authorization Service): Enables the service to authenticate and enforce access control based on the user. It implements a Java version of the standard plugable authentication Module (PAM) framework and supports user-based authorization. The Java Authorization Service Provider contract for Containers (JACC) defines the protocol between the Java EE Application Server and the authorized service provider. Allows the customization of the authorized service provider to be inserted into any Java EE product.
-
- 9.JMX (Java Management Extension): The Java Platform Enterprise Edition management specification defines an API to manage Java EE servers through a special managed EJB. The JMX API also provides some administrative support.
111. How do you understand control inversion (IoC) and Dependency injection (DI)?
A: Control reversals (inversion of control, IoC) is the call to the container of objects that have traditionally been manipulated directly by the program code, which implements the Assembly and management of the object components through the container. The so-called "inversion of Control" is the transfer of control over the Component object, from the program code itself to the external container, the container to create the object and to manage the dependencies between the objects. The IOC embodies the Hollywood principle: "Don t call me, we'll call you." The basic principle of dependency injection (Dependency Injection,di) is that application components should not be responsible for locating resources or other dependent collaboration objects. The work of the configuration object should be handled by the container, and the logic for finding the resource should be extracted from the code of the application component and given to the container. DI is a more accurate description of the IOC, that is, the dependencies between components are determined by the container at run time, in the image, that is, the container dynamically injects some kind of dependency into the component.
For example, if a class A needs to use the method in interface B, then it is necessary to establish an association or dependency for Class A and interface B, and the most primitive method is to create an instance of the implementation class C of interface B in Class A, but this method requires the developer to maintain the dependency between them. This means you need to modify the code and rebuild the entire system when the dependencies change. If you are managing the dependencies of these objects and objects through a container, you only need to define the method (constructor or setter method) that is used to associate interface B in Class A, put the implementation Class C of Class A and interface B into the container, and implement the association between the containers by configuring them.
112. Please name the implementation mechanism of dependency injection and AOP in spring.
For:
- The ways to implement dependency injection include: constructor injection, value injection, and interface (callback) injection. In spring, the IOC can be implemented by setting value injection (setter method injection) and constructor injection, which is recommended for setting value injection.
- The ways to implement AOP include: Compile-time AOP (requires a special compiler), runtime AOP (proxy mode), and load-time AOP (requires a special ClassLoader). The runtime AOP is used in spring, and the original code is enhanced by the proxy approach. For classes that implement an interface, spring is enhanced with a dynamic proxy for Java (refer to the proxy class and the Invocationhandler interface), and for classes that do not implement an interface, Spring uses the third-party bytecode generation tool, Cglib, The legacy code is enhanced by inheritance.
113. What is the reason for your project to choose to use the spring framework?
For:
-
- The 1.Spring offers a one-stop choice for enterprise-class development, with a large selection of functional modules and a free choice based on the needs of the project. Spring simplifies Java EE development with Pojo, and low-intrusive programming provides continuous integration and ease of testing of code.
-
- The core function of the 2.Spring framework is Dependency injection (DI). DI makes unit testing of code more convenient, better system maintenance, and more flexible code. The DI code itself is easy to test by constructing a black-box test that implements the "mock" object of the interface that the application needs to function. The DI code is also easier to reuse because its "dependent" functionality is encapsulated in well-defined interfaces, allowing other objects to be inserted into the desired objects as needed, which are configured in other application platforms. Di makes the code more flexible, and because of its innate loose coupling, it allows programmers to decide how to correlate objects by simply considering the interfaces they need and the interfaces exposed by other modules.
-
- 3.Spring supports aspect-oriented programming (AOP), which allows for the development of cohesion by separating the application of business logic and system services. AOP is commonly used to support features such as logging, auditing, performance, and memory monitoring.
-
- The 4.Spring also provides a number of template classes that implement basic functionality, making it easier to develop Java EE applications. For example, the JdbcTemplate class and the JDBC, Jpatemplate class, and Jpa,jmstemplate classes and JMS can all be used well together. The Resttemplate class is very concise, and the code that uses this template is very readable and maintainable as well.
-
- 5.Spring provides declarative transaction processing, job scheduling, identity authentication, a mature web MVC framework, and integration with other frameworks such as Hibernate, MyBatis, JasperReports, JSF, Struts, Tapestry, Seam and quartz and so on.
-
- 6.Spring Bean objects can be shared between different jvms through terracotta. This allows the use of existing beans to be shared in the cluster, the spring application context event into a distributed event, and the ability to export cluster beans through spring jmx, making the spring application highly available and clustered.
-
- 7.Spring prefers to use non-inspected exceptions (run-time exceptions) and to reduce improper try, catch, and finally block of code, such as the spring template class Jpatemplate, which is responsible for shutting down or releasing the database connection. This avoids potential external resource leaks and improves the readability of the code.
"Java basic question" "03"