Java Fragmented Knowledge points

Source: Internet
Author: User

Java fragmented knowledge point one: Array 1. Efficiency comparison of several methods of array copying

Efficiency: system.arraycopy > Clone > Arrays.copyof > For loop

For loop

For loop, the least efficient.

System.arrycopy ()

System.arraycopy () can be seen in the source code is native method: Native keyword Description of the method is an original ecological method, the corresponding implementation of the method is not in the current file, but in other languages (such as C and C + +) implementation of the file. The native method can be likened to a Java program's interface to a C program.

public static native void arraycopy(Object src,  int  srcPos,           
Arrays.copyof ()

From the source, you can see that the Arraycopy method is essentially called. , then its efficiency must be inferior to arraycopy.

copyOf(int[] original, int newLength) {   int[] copy = new int[newLength];   00,   Math.min(original.length, newLength));   return copy;}
Using the Clone method

Clone () Full definition: Protected native object Clone () throws Clonenotsupportedexception; only the Clone () method of the object[] array returns the object type, The subclass overrides the method of the parent class.
and Clone () and system.arraycopy are only from the experimental results that the system.arraycopy efficiency is high.

2.arrays.aslist () method

Converts an array into a list object, which returns an object of type ArrayList, which is not a java.util.ArrayList class, but a static inner class of the arrays class ! Use this object to add the delete update operation to the list, the unsupportedoperationexception exception will be reported. is still essentially an array.

Two: Class name 1. Name-related issues with class names
    1. Method is the same as the class name, and the only difference to the constructor method is that the constructor does not return a value and the method can have a return value.
public class testconstructor{Public testconstructor() {System. out. println("Constructor"); } public void testconstructor() {System. out. println("not constructor");} public static void main(string[] args) {TestConstructor TestConstructor = new testconstructor() ; System. out. println("Main"); TestConstructor. testconstructor() ;}
Three: The life cycle of Servlet1.servlet

The life cycle of a servlet can be divided into three stages: initialization phase, run phase and destruction phase.

    1. Init (): Executes only once and is responsible for initializing the Servlet object when the servlet is loaded
    2. Service (): The core method, General HttpServlet will have get,post two kinds of processing methods. The ServletRequest and Servletresponse request and response objects are constructed as parameters when the Doget and Dopost methods are called.
    3. Destory (): Executes when a servlet is stopped and unloaded, responsible for freeing resources

Initialization phase: The servlet starts, reads information from the configuration file, constructs the specified Servlet object, creates a ServletConfig object, and invokes the Init () method as a parameter for ServletConfig.

IV: Parameter passing

When the argument is a reference type: only the internal modification of the reference object will affect the original object, if the reference is modified directly, then the original object has no effect, the only effect is: This modified reference, is now not the original object reference, but a reference to the new object.
Reference passing refers to the passing of a reference to an object. If you operate on the internal members of the reference, it will directly affect the original object, but if you direct this reference to other objects, then I'm sorry, this reference has nothing to do with the previous object, and it represents only the newly directed object.

Java Fragmented 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.