Review Java Knowledge points

Source: Internet
Author: User

  1. Overloading, overwriting (overriding)

    Overloading is the representation of a class's polymorphism mainly in the method overloads, the same method name, the parameter type, how many different, the return value can be the same

    overriding (overriding) is to make some modifications to the methods of the parent class, which must be the same name, parameter, and return type. You can use super to elicit the parent class; Note: The modifier permissions of a subclass cannot be less than the parent class, the parent method of private, the final parent method cannot be overridden, and the range of exceptions thrown is only smaller

  2. Interfaces (interface) and abstract classes: Classes can inherit only one, interfaces can implement multiple, interfaces belong to special abstract classes

    The concepts of interfaces and abstract classes are different. An interface is an abstraction of an action, and an abstract class is an abstraction of the root.
    The abstract class represents what this object is. The interface represents what this object can do. For example, men, women, these two classes (if it's a class ...) ), their abstract class is human. Description, they are all human.
    People can eat, dogs can eat, you can define "eat" as an interface, and then let these classes to implement it.
    Therefore, in high-level languages, a class can inherit only one class (abstract class) (just as people cannot be both biological and non-living), but can implement multiple interfaces (eating interfaces, walking interfaces).

    The methods of abstract classes can be abstract and non-abstract, which can be public

    Interface must be public, abstract, static, final

  3. The difference between string a= "s", String C=new string ("s"), new StringBuffer ("s")

    All strings that are directly assigned are in the same link pool, the references are the same, and the new string ("s") creates a new reference each time

    So String b= "s" a==b A.equals (b) are true; A==c is False a.equals (c) is true

    Both of these methods are immutable and cannot be directly spliced.

    The length of new StringBuffer ("s") is variable and can be arbitrarily spliced

  4. Collection (class-based): interface is List (ordered): The implementation class is vector, Set (unordered, different)

    The difference between a list and a vector is that the former is highly efficient, the thread is unsafe, the latter is synchronous

    Map does not belong to collection!!

  5. Spring's AOP (Dependency injection)

    AOP injection is mainly divided into: interface injection, structure injection, attribute injection (getter, setter: Also become set value injection)

    When injected for construction, other objects of this object take precedence (priority Dependency injection)

    When injected for setpoint, it is simple and intuitive to instantiate the object and then instantiate the dependent object (which is the first instance of dependency injection).

    When setting value injection, construction injection coexistence. The former is preferred, and the current object is first created

  6. HttpServletRequest and HttpServletResponse

    HttpServletRequest inheritance and ServletRequest, you can use the Servlet method (Doget, Dopost )

    Main methods: Getauthtype (); ---Returns the name of the certificate configuration to protect the servlet

    Getcontextpath ();---Returns the URI of the partial request indicating the corresponding relationship of the context

    GetCookies ();---Returns an array that includes the request cookie object sent by all clients

    Getdateheader (java.lang.String name);--Returns the specified request header value and depicts the Date object with a long integer

    GetHeader (java.lang.String name);--Returns the specified request header file as a character type

    Getheadernames ();--return this request container all header file names using enumeration method

    Getheaders (java.lang.String name);--Returns the enumeration of all values of the specified file header with a character-type Object

    Getintheader (java.lang.String name);--Returns the value of the specified request file with the integer type

    GetMethod ();--Returns the name of the HTTP method that handles this request

    GetPathInfo ();--When a client sends a URL request, it returns the additional information path associated with it

    GetPathTranslated ();--Return some extended path information after the servlet name, but convert it to his real address before query string

    GetQueryString ();--Returns a query string after it is contained in the request URL

    Getremoteuser ();--Returns the user's registration using this request, or null if the user has passed validation or failed validation

    Getrequestedsessionid ();--Returns the session Id of the specified user

    Getrequesturi ();--return part of the URL of this request from the name of this protocol to the first line of the HTTP request query string

    Getrequesturl ();--re-establishing the URL when requested by the client

    Getservletpath ();--return part of this request URL call servlet

    GetSession ();--Returns the session associated with the current request if the request does not have a session to create a

    GetSession (Boolean Create),---Returns the httpsession associated with this request, and if no session is created he is true and returns to the new session

    Getuserprincipal ();--Returns an object of type Java.security.Principal Aohan the currently authenticated user name

    Isreqeustedsessionidfromcookie ();--check if the session ID of this request is from a cookie

    Isrequestedsessionidfromurl ();--Check whether the request for this session Id is from a partially requested URL

    Isrequestedsessionidvalid ();--Check if the session ID of the request is valid

    IsUserInRole (java.lang.String role);--Returns a Boolean flag used to determine whether the authenticated user is covered by the established role

    The following begins HttpServletResponse (the object can send three types of data to the client: A. Response Header B. Status code c. Data)

    Common applications:

    A. Use OutputStream to write Chinese to the client:
    String data = "China";
    OutputStream stream = Response.getoutputstream ();//Gets a stream that writes data to the response object, and when the Tomcat server responds, the data in the response is written to the browser
    Stream.Write (Data.getbytes ("UTF-8"));
    At this time in the HTML page will appear garbled, because: the server will "China" according to the UTF-8 Code table encoding, the corresponding code value is assumed to be 98, 99, the server will send the code value to the browser. The browser is decoded by default according to GB2312, and the corresponding character in the GB2312 code table is not "China"
    The correct code is as follows:
    Response.setheader ("Content-type", "text/html;charset=utf-8");//Send a response header to the browser, set the browser to decode by UTF-8
    String data = "China";
    OutputStream stream = Response.getoutputstream ();
    Stream.Write (Data.getbytes ("UTF-8"));
    B. Use writer to write Chinese to the client:
    PrintWriter writer = Response.getwriter ();
    Writer.write ("China");//garbled, because when we write "China" to the response object, the Tomcat server must encode it in order to transmit the data over the network to the browser, because no encoding is specified, the default is Iso8859-1 ,
    When the browser receives the data, according to GBK decoding must appear garbled
    The correct code is as follows:
    Response.setcharacterencoding ("Utf_8");//Setup response is encoded as UTF-8
    Response.setheader ("Content-type", "text/html;charset=utf-8");//Send a response header to the browser, set the browser decoding method for the UTF-8, actually set the sentence, Response is also set by default to encode the UTF-8, but the best two sentences in development are used together
    Response.setcontenttype ("Text/html;charset=utf-8"); the same as the code in the same sentence
    PrintWriter writer = Response.getwriter ();
    Writer.write ("China");
    C. Using response for file download:
    String Path = This.getServletContext.getRealPath ("/China. jpg");
    String fileName = path.substring (path.lastindexof ("\ \"));
    Response.setheader ("Content-disposition", "Attachment;filename" +urlencode r.encode (filename, "UTF-8"));//Set the response header, Tell the browser that the response is a download response, and if the file name contains Chinese, you must use URL encoding ... Read and write to a file

Review Java Knowledge points

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.