Java Face question 03

Source: Internet
Author: User
Tags modifiers

1.web Development

( 1 ) briefly servlet The life cycle

Servlet life cycle: servlet loading---> Instantiation---> Processing requests---> destroying.

Init (): The init () method is executed only once in the servlet's life cycle. It is executed when the server loads the servlet and is responsible for initializing the Servlet object. You can configure the server to get the servlet into the servlet at the start of the server or client for the first time. Init () is not repeated regardless of how many clients access the servlet.

Service (): It is the core of the servlet and is responsible for processing customer requests. Every time a customer requests a HttpServlet object, the service () method of the object is called. The service () method already exists in HttpServlet. The default service function is to invoke the Doget or Dopost function corresponding to the method of the HTTP request.

Destroy (): Executes only once, and executes the method when the server-side stops and the servlet is unloaded. When a Servlet object exits its lifecycle, it is responsible for releasing the resource that is occupied.

( 2 ) Session Use of: servlet in Create, destroy Session the statement, how to get from Session value in

Create Session:httpsession session=reqest.getsession ();

Destruction of Session:session.invalidate ();

Gets the value in session: Session.getattribute (String name); The return value is of type object.

( 3 ) Brief introduction of Filters Filter and listeners Listener the Difference

Filter (filter)

It is the most practical technology in Servlet technology, Web developers through the filter technology, Web server management of all Web resources: such as JSP, Servlet, static picture files or static HTML files, and so on to achieve some special functions. For example, the implementation of URL-level access control, filtering sensitive words, compressed response information and other advanced features.

It is mainly used to preprocess user requests, or to post-process httpservletresponse. Use the full process of filter: Filter to preprocess the user request, then send the request to the servlet for processing and generate a response, and finally filter to post-process the server response.

Filter function:

Intercept the client's httpservletrequest before HttpServletRequest arrives at the Servlet. You can also modify the HttpServletRequest header and data as needed to check the httpservletrequest.

Intercept HttpServletResponse before HttpServletResponse arrives at the client. You can also modify the HttpServletResponse header and data as needed to check the httpservletresponse.

Listener:

The listener is actually a class that implements a specific interface and then describes the class in the Web. xml file so that the server can instantiate the class and start the listener when it is started. When the state of the scope object changes, the server automatically invokes the method in the Listener object.

Function:

Statistics on the number of people online and online users; the initialization of information when the system is loaded; The number of visits to the website; combined with spring

2.java Basic

( 1 ) Description HashSet and the HashMap the Relationship

HashSet implements the set interface, storing objects unique, unordered, stored elements are unordered, is a non-thread-safe, and allows a value of NULL;

HashMap implements the map collection, storing elements in the form of key-value (key-value) pairs, where key is not ordered, but cannot be duplicated, and value does not require order but can be duplicated;

( 2 ) Description HashMap and the hashTable the difference, how will HashMap Programmatic thread Synchronization

difference: HashMap inherits the abstractmap,hashtable inherits the dictionary class, both of which implement the set interface; HashMap is non-thread-safe and hashtable is thread-safe. ; HashMap method is not synchronize, multithreaded access requires an external synchronization method, Hashtable method is synchronize;hashmap allow null keys and values, Hashtable does not allow null keys and values ; The efficiency of HASHMAP is higher than that of Hashtable, HashMap has Containsvalue and ContainsKey methods, Hashtable method.

HashMap Thread Synchronization :

Map map = Collections.synchronizedmap (new HashMap ());

( 3 ) Public , Private , Static , Final Description of the usage scenario

Public and private are access modifiers that control external access to members within the class.

Public: Indicates that the object members are fully shared and accessible to the outside world.

Private: Indicates that the object member is completely private, does not allow any outside access, only this class can access, the outside world can be accessed through the Set/get method provided by this class.

Static and final are modifiers that control the change of class members

Static: A modified method or variable belongs to a class, is shared by all classes, is only executed once when the class is loaded, and non-static methods can directly access static methods as well as non-static methods. Static methods can not directly access non-static methods;

Final: You can declare classes, member variables, and member methods by using the final keyword, and once declared, they are non-inheritable, non-modifiable, and cannot be overwritten. When modifying a method, the method cannot be overridden, the property cannot be changed when the property is modified, the property is divided into objects and basic types, and the modified base type indicates that the base type assignment cannot be assigned again, and the decorated object indicates that the property cannot point to another object (the reference is not changed). But the object he is pointing to can still be changed.

3. Front-end development ------AJAX principles explained

Ajax works by adding a middle-tier (Ajax engine) between the user and the server, sending an asynchronous request to the server through the XMLHttpRequest object, getting the data from the server, and then updating the page with JavaScript to manipulate the DOM. One of the most critical steps is to get the request data from the server and make the user action and the server response asynchronous.

XMLHttpRequest is the core mechanism of Ajax, which was first introduced in IE5 and is a technique that supports asynchronous requests. Simply put, JavaScript can request and process responses to the server in a timely manner without blocking the user. Achieve a no-refresh effect.

XMLHttpRequest Property Introduction

onReadyStateChange event handlers for events that are triggered by each state change.

ResponseText the string form of the data returned from the server process.

Responsexml a DOM-compatible document data object that is returned from the server process.

Status number codes returned from the server, such as common 404 (not Found) and 200 (ready)

Status Text string information accompanying the state code

ReadyState Object State Value

0 (uninitialized) object has been established but not initialized (the open method has not been called)

1 (Initialize) object has been established, the Send method has not been called

2 (send data) The Send method has been called, but the current state and HTTP headers are unknown

3 (data transfer) has received some of the data, because the response and HTTP header is not complete, then through Responsebody and ResponseText to obtain some of the data will be error,

4 (complete) The data is received, at which time the complete response data can be obtained by Responsexml and ResponseText

Code writing:

function Createxmlhttp () {

Non-IE browser creates XMLHttpRequest object
if (window. XMLHttpRequest) {
XMLHTTP = new XMLHttpRequest ();
}

IE Browser creates XMLHttpRequest object
if (window. ActiveXObject) {
try {
XMLHTTP = Newactivexobject ("Microsoft.XMLHTTP");
}
catch (e) {
try {
XMLHTTP = new ActiveXObject ("MSXML2. XMLHTTP ");
}
catch (ex) {}
}
}
}

function Ustbwuyi () {

var data =document.getelementbyid ("username"). Value;
Createxmlhttp ();
if (!xmlhttp) {
Alert ("Create XMLHTTP Object Exception! ");
return false;
}

Xmlhttp.open ("POST", url, false);

Xmlhttp.onreadystatechange = function () {
if (xmlhttp.readystate = = 4) {
document.getElementById ("user1"). InnerHTML = "Data loading ...";
if (Xmlhttp.status = = 200) {
document.write (Xmlhttp.responsetext);
}
}
}
Xmlhttp.send ();
}

4.DB Database

(Scene one) there is a table A , which has a field Col , the value stored is a,b,c,d ; Request for investigation A the records in the table, the Col to be A the display is OK , B the display is NO, the other display is Other , write SQL Statement

Select Decode (Col,a,ok,b,no,other)

From A;

(Scene Two) there are two tables P,c , C the table has Number the field name of the type is value , P as the parent table, C as a child table, P with C the relationship is 1 the N ;

Requirements: Query the number of records for the parent table (condition: the corresponding child table value value >300 ); Write SQL Statement

Select COUNT (0)

From P p,c C

where c.value>300;

5. Open Source Framework

( 1 ) Hibernate in the Session Close the root cause and solution of the problem;

Hibernate's opencurrentsession will automatically close the session after commit or rollback.

The solution adopts Opensesioninview mode; Ensure that each user's request is kept in a session open

( 2 ) describes Spring transaction mechanism, and say the implementation principle?

The two most important features of a transaction are the level of communication and the data isolation levels of the transaction. The propagation level defines the scope of control of the transaction, and the transaction isolation level defines the scope of the transaction's control over the database read and write.

7 levels of propagation for a transaction:

A. propagation_required, the default spring transaction propagation level, which is characterized by the addition of transactions to the transaction if a transaction already exists in the context, and the execution of a new transaction if no transaction exists in the current context.

B.propagation_supports, the propagation level is characterized by the support for transaction join transactions if there is a transaction in the context, and non-transactional execution if there is no transaction. So, not all of the packages in the Transactiontemplate.execute code will have transactional support. This is often used to deal with non-core business logic operations that are not atomic in nature. Fewer scenarios.

C.propagation_mandatory, there must be a transaction in the context of this level of transaction requirements, or an exception will be thrown! Configuring the propagation level of this mode is a guarantee of effective control context calling code omission to add transaction control. D.propagation_requires_new, the propagation level is characterized by a new transaction being created each time, and the transaction in the context is suspended at the same time, and after execution of the current new transaction completes, the context transaction resumes execution.

E.propagation_not_supported, the current level is characterized by the presence of transactions in the context, suspending transactions, executing the current logic, and resuming the context of the transaction after the end.

F.propagation_never, the transaction is more stringent, the above transaction propagation level is just not supported, there is a transaction suspended, and the Propagation_never propagation level requires the context of the transaction cannot exist, once the transaction, throw runtime exception, Force Stop Execution!

g.propagation_nested, you can literally know, NESTED, nested-level transactions. The propagation level feature is that if a transaction exists in the context, the nested transaction executes, and if there is no transaction, the transaction is created.

The data isolation level is divided into four different types:

A.serializable: The most stringent level, the transaction serial execution, the resource consumes the most;

B.repeatable read: Guarantees that a transaction does not modify data that has been read by another transaction but not committed (rolled back). "Dirty reads" and "non-repeatable reads" are avoided, but more performance losses are incurred.

C.read COMMITTED: The default transaction level for most mainstream databases ensures that one transaction does not read to another data that has been modified but not committed by a parallel transaction, avoiding "dirty reads". This level applies to most systems.

D.read UNCOMMITTED: Ensures that illegal data is not read during the read process.

Implementation principle:

The spring configuration file about transaction configuration is always composed of three components, namely, DataSource, TransactionManager and agent mechanism of the three parts, regardless of which configuration method, the general change is only the agent mechanism this part.

DataSource, TransactionManager These two parts only according to the data access way change, for example uses Hibernate to carry on the data access, DataSource actually is sessionfactory, The implementation of TransactionManager is Hibernatetransactionmanager.

Depending on the proxy mechanism, there are several different ways in which spring transactions are configured:

The first way: Each bean has a proxy

Second way: All beans share a proxy base class

Third Way: Using interceptors

Fourth way: Interceptors configured with the TX tag

Fifth way: Full annotation

( 3 ) using Struts2 complete a Login processing: How are parameters received? How does the checksum of the view layer work? How the validation of the business layer is done and the processing process is explained

Parameter acceptance:

Action class parameter acceptance method:

(1) attribute receive: Directly through

(2) JavaBean Accept: Accept the parameters passed by the page by declaring the object

(3) By implementing the Modeldriven interface: Overriding the Getmodel method to obtain the Parameter object

Check of the View layer

The view layer can use JS to get the user input content, verify the reasonable before submitting or give a hint, or use jquery asynchronous authentication.

Validation of the business layer

Business layer validation Using validation framework, Action class inheritance Actionsupport

You can override the Validate () method with global validation, or you can write a Validatelogin () method and verify the specific login method.

6. Object- oriented

Use the concept of object-oriented to explain the following things

Wood, table, Chair, table leg, table at office door, Square chair

The interface of wood-oriented object;

Tables and chairs achieve the type of wood interface;

A table leg is a property in a table class;

The desk at the door of the office is the object of the table class;

A round chair is an inner class in a chair class.

7.[ analysis ]hibernate usage Scenarios for:

DB in 5 a record with a different primary key, DAO Layer through Hibernate put this 5 The record is constructed as a corresponding Pojo back to the control layer, the control layer 5 a Pojo re-assembled as HashSet when the object is returned to the view layer for display, the discovery page displays only the 3 record, what do you think may be the cause of it?

The HashSet collection stores a collection of unique, unordered objects, stored objects that do not allow duplicates, but are allowed to be empty, and whether or not the same values are judged by equals.

This may be because the stored record has a value of two, or because it stores a null value;

8. After a week, the project manager assigned the task to you, the content of the task is to add a new * * function for an existing module , it is expected that you two days after the completion, but the actual implementation of the process you have completed the task in one day, What do you plan to do for the rest of the day?

9. which project has the greatest harvest in the past work? What is the harvest? What kind of role do you play in it? Do you know what you're doing in the project? Detailed

briefly talk about the new technology you've been learning recently .

Java Face question 03

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.