Go Java Common Concept Solutions

Source: Internet
Author: User
Tags finally block

1. What is a transaction?

A transaction is a series of operations performed as a logical unit, and a logical work cell must have four properties called ACID (Atomicity,

Consistency, isolation, and persistence) to become a transaction:

Atomic Nature

The transaction must be an atomic unit of work, either all executed or not executed for its data modification.

Consistency

When a transaction is complete, you must keep all data in a consistent state. In the related database, all rules must be applied to the modification of the transaction

To maintain the integrity of all data. At the end of a transaction, all internal data structures, such as B-tree indexes or doubly linked lists, must be positive

The correct.

Isolation of

Modifications made by concurrent transactions must be isolated from modifications made by any other concurrent transaction. The state in which the data is located when the transaction views the data, or

Is the state before another concurrent transaction modifies it, or the state after which another transaction modifies it, and the transaction does not view the data in the middle state.

This is called serializable because it is able to reload the starting data and replay a series of transactions so that the state at the end of the data and the original

The same status as the service execution.

Durability

After the transaction is complete, its effect on the system is permanent. This modification will persist even if a system failure occurs.

2. How can I optimize conditional queries in the database when they are very slow?

1. Build an index
2. Reduce the association between tables
3. Optimize SQL, try to get SQL to locate data quickly, do not let SQL do the full table query, should go index, the data volume of the table in front
4. Simplify the query fields, no useless fields, have control over the returned results, and try to return a small amount of data

3. Session.load () and session.get () differences

The Session.load/get method can read records from the database based on the specified entity class and ID , and returns the corresponding entity object. The difference is:
1) If a record that matches the condition is not found, the Get method returns NULL, and the load method throws a objectnotfoundexception.
2) The Load method returns an instance of the entity's proxy class, and the Get method always returns the entity class directly.
3) The Load method can take full advantage of the existing data in the internal cache and the level two cache, while the Get method only makes data lookups in the internal cache, and if no corresponding data is found, it passes through the level two cache and directly invokes SQL to complete the data read.

4. Say the life cycle of the servlet

a: Positioning: The user requests the specified servlet based on the address, Web. XML navigates to a specific servlet based on the address entered by the user.
b: Load: Loads the found servlet class into the Web container (servle T container).
c: instantiation: Calling the default parameterless constructor. Implements the instantiation of the servlet.
d: Initialize: Call the Init method, Implements the initialization of member variables.
e: Service handling: Servlet's service method receives user requests Whether a get or post,service automatically passes the user request to the Doget and Dopost methods, depending on how the current user requests it. After processing is complete, the response results are generated.
f: Destroy: Call the Destroy method, Implementation of the servlet release effort.
release when the server shuts down. Or the servlet produces a change before reloading to release the original servlet.

Note: In a servlet container, a servlet will only produce one instance object to work on.

5. Talk about final, finally, finalize the difference.

Final modifier (keyword) If a class is declared final, it means that it can no longer derive a new subclass and cannot be used as a parent

Class is inherited. Therefore, a class cannot be declared abstract and declared final. Declares a variable or method to be final,

It is guaranteed that they will not be changed in use. A variable declared final must be given an initial value at the time of Declaration, and in a subsequent reference only

Read, not modifiable. The method that is declared final is also used only and cannot be overloaded.

Finally? Provides a finally block to perform any cleanup operations when the exception is processed. If an exception is thrown, then the matching

The catch clause executes, and then the control enters the finally block, if any.

Finalize? Method name. Java technology allows the Finalize () method to be used before the garbage collector clears objects from memory

Do the necessary cleanup work. This method is called by the garbage collector to this object when it determines that the object is not referenced. It is in

is defined in the Object class, so all classes inherit it. Subclasses override the Finalize () method to organize system resources or perform their

He cleaned up his work. The Finalize () method is called on the object before the object is deleted by the garbage collector.

6. Why use the Hibernate,hibernate execution process.

1. Encapsulates JDBC, simplifying many of the repetitive code.
2. The DAO layer coding has been simplified to make development more object-enabled.
3. Good portability, support a variety of databases , if you change a database as long as the configuration file to transform the configuration can be, do not change hibernate code.
4. Support transparent persistence, because Hibernate operates purely (Pojo)Java classes, without implementing any interfaces, without intrusion. So it's a lightweight framework.

Hibernate execution Process:

1. Through the configuration (). Configure (); Read and parse the Hibernate.cfg.xml config file.
2. parse the mapping information from the read in hibernate. Cfg.xml.
3. Through Config.buildsessionfactory ();//Get sessionfactory.
4. Sessionfactory.opensession ();//Get session.
5. Session.begintransaction ();//Open transaction.
6. Persistent operate;
7. Session.gettransaction (). commit ();//COMMIT Transaction
8. Close the session;
9. Close the sessionfactory;

Two handwritten programming questions

1. Implement a calculator console program in C + +, Java, C #, or vb.net any object-oriented language, requiring input of two numbers and operators to get results.

2. Write a code validation stringbuffer, string string connection performance Difference

String tempstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int times=5000;

Long here1= system.currenttimemillis ();

String str = "";

for (int i = 0; i < times;i++) {

Str =str+ TEMPSTR;

}

Long here2= system.currenttimemillis ();

Long time = (here2-here1);

System.out.println ("The above code execution requires" +time+ "milliseconds");

Long here1= system.currenttimemillis ();

StringBuffer sb = new StringBuffer ();

for (int i = 0; I < times; i++) {

Sb.append (TEMPSTR);

}

Long here2= system.currenttimemillis ();

long time = (here2-here1);

System.out.println ("The above code execution requires" +time+ "milliseconds");

1.servlet life cycle?
A: The servlet has a good definition of lifetime, including loading and instantiation, initialization, processing requests, and end of service.    This lifetime is expressed by the init,service and destroy methods of the Javax.servlet.Servlet interface. The Web container loads the servlet, beginning with the life cycle.
The servlet is initialized by calling the servlet's init () method.
by invoking the service () method implementation, different do*** () methods are called depending on the request. To end the service, the Web container invokes the servlet's Destroy () method. 2. What are the general implementations of the servlet implementation? Answer: public void init (servletconfig config) public servletconfig getservletconfig () public String getservletinfo ()
Public void Service (ServletRequest request,servletresponse response) public void Destroy ()
3. Say the servlet's life cycle and tell the difference between servlet and CGI.
when the servlet is instantiated by the server, the container runs its Init method, the service method is run when the request arrives, and the service method automatically dispatches the Doxxx method (Doget,dopost) corresponding to the request, etc. The Destroy method is called when the server decides to destroy the instance. The difference from CGI is that the servlet is in a server process, it runs its service method in a multithreaded manner, one instance can serve multiple requests, and its instances are generally not destroyed, and CGI generates a new process for each request, which is destroyed after the service is completed. So the efficiency is lower than the servlet.
2. Briefly describe the relationship between JSP and servlet. Java servlet is the foundation of JSP Technology, and the development of large Web applications requires Java servlet and JSP mates to complete. Many Web servers now support Servlets, even if they do not directly support Servlet Web servers, but can also support servlets through the application servers and modules of the attachment, thanks to the cross-platform nature of Java. In addition, because the servlet internally provides services in a threaded manner, it is not necessary to start a process for each request, and the multithreading mechanism can serve multiple requests at the same time, so the servlet is highly efficient.
4. What are the similarities and differences between JSP and servlet, and what are their connections? JSP is the extension of servlet technology, which is essentially a simple way for servlets to emphasize the appearance of application. The JSP is compiled with a "class servlet". 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 JSP scenario is that Java and HTML can
into a file with a. jsp extension. JSPs focus on Views, and Servlets are used primarily for control logic.  5. How do the various parts of MVC have the technology to implement?
Answer: MVC is shorthand for Model-view-controller. "Model" represents the business logic of the application (implemented through the JAVABEAN,EJB component), "View" is the presentation face of the application (generated by the JSP page), and "Controller" is the process control that provides the application (typically a servlet), Through this design model, the application logic, processing and display logic are divided into different component implementations.  These components can be interacted with and reused.
6. What are the built-in objects for JSP? What are the roles?
A : JSP has the following 9 basic built-in components (which can correspond to the 6 internal components of ASP): (1 request) The request object of the HttpServletRequest class.
function: Represents the Request object, which contains the parameters from the Get/post request. Primarily used to accept data that is transmitted to the server side by the client over an HTTP protocol connection.  It contains information about the browser request and provides several useful ways to get the cookie, header, and session data.
(2 response) The Respone object of the HttpServletResponse class.
function: Represents the Response object, which is used primarily to send data to the client.     The Web page returns to the client's response and provides several methods for setting the response to the browser (such as cookies, header information, etc.) (3 out) of the JspWriter class's out object.  Function: Mainly used to output data to the client (to transmit the output of the response); The base class for out is JspWriter and provides several methods that you can use to echo the output to the browser. (4 session) The session object of the HttpSession class.
function: Mainly used to save each user information separately, the session associated with the request, session state maintenance is the Web application developers must face the problem.
(5 Applicaton) application objects of the Servletcontex class
function: Mainly used to save user information, code fragment of the running environment; it is a shared built-in object, where multiple users in a container share a Application object. So the information it saves is shared by all users. This helps to find information about the servlet engine and the servlet environment .
(6 PageContext) PageContext objects of the PageContext class
Role: Manage page properties, wrap page contexts for JSP pages, manage access to named objects in a particular visible part of the JSP, and create and initialize the container.   (7 config) The Config object for the ServletConfig class.
role: A code Snippet Configuration object that represents the configuration of the servlet. This object is used to access the initialization parameters of the servlet instance.

(8 page) the page (equivalent this) object of the object class.
role: Processing JSP Web page (JSP Web page itself), is an instance of the object class, refers to the JSP implementation class instance (represents a servlet instance generated from the page), that is, it is also the JSP itself, only within the scope of the JSP page is legitimate. (9 Exception) functions: Handles errors and exceptions that occur when JSP files are executed, the built-in objects and methods of 7.JSP for error pages, not captured exceptions.
The request request represents the HttpServletRequest object.  It contains information about the browser request and provides several useful ways to get the cookie, header, and session data.
response response represents the HttpServletResponse object and provides several methods for setting the response to the browser (such as cookies, header information, etc.)
The Out object is an instance of Javax.jsp.JspWriter and provides several methods that you can use to echo the output to the browser. PageContext PageContext represents a Javax.servlet.jsp.PageContext object. It is used to facilitate access to a wide range of namespaces,
The API for servlet-related objects and wraps the methods of common servlet-related functionality.
the session session represents a requested Javax.servlet.http.HttpSession object. Session can store the user's state information application Applicaton represents a Javax.servle.ServletContext object. This helps to find information about the servlet engine and the servlet environment
The config config represents a Javax.servlet.ServletConfig object.     This object is used to access the initialization parameters of the servlet instance.  Page page represents a servlet instance generated from this page 8, what are the actions of JSP? What are the roles? A: JSP has the following 6 basic actions
jsp:include: A file is introduced when the page is requested.    Jsp:usebean: Find or instantiate a JavaBean.  Jsp:setproperty: Sets the properties of the JavaBean.
Jsp:getproperty: Outputs the properties of a JavaBean.  Jsp:forward: Move the request to a new page.
Jsp:plugin: The Main method for generating an object or embed tag 9, the request object, based on the browser type for the Java plug-in:
SetAttribute (String name,object): Sets the parameter value of the request named name GetAttribute (string name): Returns the property value specified by name
getattributenames (): Returns a collection of names of all properties of the request object, resulting in an instance of an enumeration

Go Java Common Concept Solutions

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.