Review of Java Knowledge (IV.)

Source: Internet
Author: User
Tags set time

Recently ready to move, but also to review the basic knowledge. After a year, the front just contact with the Springboot can only be released first. Just review what you have listed.

the elements in Set cannot be duplicated , So what is the way to distinguish between duplicates or not? is to use == or is equals ()? What difference do they have ? ? with contains to distinguish whether there are duplicate objects. Or not.

The Hashcode method is called first when comparing, and if it is not the same, the proof is not equal.

If the same, then call the Equals method, if the Equals method is the same, proving equal, not identical, proving unequal.

= =: Mainly used in basic data types and references

Equals: is primarily a comparison of object or object references.

Whether a collection contains an element is judged by the contains.

What is the difference between sleep () and wait ()?

-Have different objects

-wait can release object locks, sleep preserves object locks

-wait can be any object to invoke, and sleep can only be called when the thread

-wait can be awakened by notify at any time, sleep can only wait for a set time to wake up naturally, otherwise an exception will be thrown

-wait must be called in a synchronous method or in a synchronous block, and sleep can be called at any location

The nine large built-in objects and methods of JSP

R equest the request represents the HttpServletRequest object. Take client form field information and cookies, header, and session

Response Response represents the HttpServletResponse object, returning text and writing cookies to the client's response.

out-out prints HTML text to the client.

PageContext : The context of the current JSP page, you can get the session, request, application and other built-in objects, in the custom tags used a lot.

The session session represents a requested Javax.servlet.http.HttpSession object. Session One user multiple pages share the same variable.

Application Applicaton represents a Javax.servle.ServletContext object. The variable that holds the container level.

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 that is generated from this page

Exception: Exception, when iserrorpage=true represents the page that appears when an exception occurs, the normal page <% @page erropage= "error.jsp"%> to specify which exception page the exception jumps to

the difference between jdbc, hibernate , and Ibatis

JDBC: Manual

Write SQL manually

Delete, insert, update to send the value of an object one by one to the SQL, you cannot pass in an object directly.

Select: Returns a resultset that is to be fetched from a row in the ResultSet, a field, and then encapsulated into an object without directly returning an object.

Features of Ibatis: Semi-automatic

SQL to write manually

Delete, insert, update: Pass in an object directly

Select: Returns an object directly

Hibernate: Fully Automatic

Do not write SQL, automatic encapsulation

Delete, insert, update: Pass in an object directly

Select: Returns an object directly

What do the core classes in spring have to do with each other ?

Beanfactory: Create a new instance that can implement a singleton pattern

Beanwrapper: Provides a unified get and set method

ApplicationContext: Provides framework implementations, including all features of the beanfactory

What does spring's IOC and AOP refer to?

IOC, full name (inverse of control), Chinese meaning: Inversion of controls, the core of the Spring framework is based on the principle of inversion of control.
Control inversion is a technique that puts the creation and management of component dependencies outside the program.
The relationship between the container control program and not directly controlled by the code

Since control is shifted from the code to the container, it is called inversion

AOP is aspect-oriented programming (AOP is the acronym for Aspect Oriented program), which is a method of dynamically cutting code into a class at run time, the programming idea at the specified location is the aspect-oriented programming.

three ways to inject the Spring IOC

1. Interface Injection

2. Getter,setter Mode Injection

3. Constructor injection

1. Interface Injection

public class ClassA {
Private Interfaceb CLZB;
public void dosomething () {
Ojbect obj = Class.forName (config.bimplementation). newinstance ();
CLZB = (interfaceb) obj;
Clzb.doit ();
}
......
}

In the above code, ClassA relies on the implementation of INTERFACEB, how to obtain an instance of the Interfaceb implementation class? The traditional approach is to create an instance of the INTERFACEB implementation class in your code and give CLZB. ClassA is dependent on the implementation of INTERFACEB at compile time. In order to separate the caller from the implementation at compile time, the above code is available.
We dynamically load the implementation class based on the class name (config.bimplementation) of the implementation class set up in the configuration file, and use it for ClassA after Interfaceb forced transformation, which is the most primitive prototype of interface injection.

public class ClassA {
Private Interfaceb CLZB;
Public Object dosomething (Interfaceb b) {
CLZB = b;
return Clzb.doit ();
}
......
}

In the above code, the task of loading an interface implementation and creating its instance is done by the container.
At run time, the INTERFACEB instance will be provided by the container. Even when the IOC concept is not yet established, such a method has frequently appeared in our code.

public class Myservlet extends HttpServlet {
public void doget (HttpServletRequest request,httpservletresponse response) throws Servletexception, IOException {
......
}
}

HttpServletRequest and HttpServletResponse instances are injected dynamically by the servlet container at run time.

2.Setter Set Injection
The dependency injection mechanism based on setup mode is more intuitive and more natural.

public class ClassA {
Private Interfaceb CLZB;
public void Setclzb (Interfaceb clzb) {
THIS.CLZB = CLZB;
}
......
}

3. Constructor injection

public class Dibyconstructor {
Private final DataSource DataSource;
Public Dibyconstructor (DataSource DS) {
This.datasource = ds;
}
......
}

constructor injection, that is, through the constructor to complete the dependency of the setting, the container by invoking the constructor method of the class to inject its required dependencies.

Review of Java Knowledge (IV.)

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.