Java fifth to Seventh Day learning content Review--java White Paper fifth chapter

Source: Internet
Author: User

The Java learning process appeared for the first time, background: tomb-Sweeping day and rain lasting 1 weeks.

  1. Method signature = Method name + parameter list.

  2. You need to be aware of the overriding method: 1. The compatibility of the method return type after overwriting; 2. The visibility of the new method must be no less than the visibility of the original method.

  3. There is a cause and effect: each invocation method is expensive to search, so the virtual opportunity in advance for each class to establish a method table, the use of Direct lookup table, in addition, in addition to the Private,static,final method, all methods are dynamic links.

  4. The actual parsing process of invoking a method is detailed in the white Paper P160;

  5. The final decorated class will not allow inheritance, and all methods in this class are equivalent to the final decoration, but the data fields are not final decorated. The final decorated method will not be allowed to be overwritten. The final decorated data field is equivalent to a const assignment that can only be initialized and cannot be changed.

  6. Purpose of the final decorated class or method: Prevents the target from changing semantics in subclasses

  7. Inline in Java produces conditions: Simple code, frequent calls, and methods that will not be overwritten.

  8. Description of the type conversion for a class: A. Only in the inheritance hierarchy. B. Subclasses can be cast to a super-class. C. When a superclass is cast to a subclass, it should be a failure. For code rigor, you should test the class object before type conversion, plus test if (the variable name instanceof needs to be converted to the type name) {conversion succeeds do}

  9. Abstract keyword--abstraction class, method.

  10. An abstract class cannot have an instance, but a reference can exist, and the reference should refer to the subclass instance of the abstract class, because the abstract class itself cannot exist as an instance. An abstract method can only be declared, cannot be defined with {}, and needs to be modified by an abstract. Detailed in the white Paper P164.

  11. A class can be defined as an abstract class, even if it does not contain an abstract method, and if an undefined abstract method is still present in the subclass, the subclass needs to use the abstract adornment and therefore cannot exist, unlike C + +, in C + +, as long as there is a pure virtual function, This class is automatically turned into an abstract class

  12. The Protect modifier keyword in Java, whose decorated content is visible to both a. Subclass B. The class in the same package, the author has mentioned that it is not recommended to use protect, but there is a situation where it is better to use protect.

  13. The object class is a subclass of all Java classes, and it is important to note that the Java array, whether it is a primitive type or an array of objects, should be treated as a class, so they are also subclasses of object.

  14. There is a cause and effect: since 13, so, a variable of type object can refer to an object instance of any class, it is important to note that there is a good chance of using (forcing type conversion) to use some methods of the original class in the use of the reference. Here is a supplementary note: In Java, only the base type is not part of the class object. Here's a comparison to C + +: There is no root class (like object in Java) in C + +, but there is a pointer (void*), and any type of pointer can be cast to such a pointer.

  15. The Equals method in the object class simply detects whether two objects refer to the same instance, and does not actually draw a conclusion based on the data field. Here's an improvement: although A.equals (b) May implement a comparison of the reference addresses of a and B, they may have a null presence, so a static method Objects.equals (A, B) can prevent this behavior, which returns the value: True when A=b=null A, B has a null when false, otherwise calls A.equals (b) and returns the corresponding structure.

  16. When overriding the superclass equals in a subclass (if needed), it needs to be instrumented with the Equals method of the superclass before comparing the unique data fields in the subclasses. Detailed with the white Paper P170, the redefinition specification for the Equals method is detailed in p179~p173;

  17. The handling of arrays is always special, where the array equals method should take advantage of the Arrays.equals static method

  18. Here's a tip: adding @override to the top of the overlay superclass method can be used to detect overwrite failures but adds an unrelated method (this is due to a parameter list error).

  19. Each class object has a hash code (so the array also has), which is obtained using the Hashcode () method or the hash method or a custom method. Where the hash code of the string class is related to its contents, so the same hash code exported by the same string object, the StringBuffer class does not overwrite the Hashcode method, so the object method is used, so the address information is obtained. Here's a note: If you overwrite the Equals method, you have to overwrite the Hashcode method at the same time, and you can see that calling the Hashcode method is required (object name). Hashcode (), this is done so that the user can insert the object into a hash table. So here's another note that the new Hashcode method needs to use them as parameters for the calculation of the data fields that are used in equals to determine whether they are equal, The. Hashcode cannot be called for a base type parameter, can be called by boxing, or it can be computed using the object static method hash (), detailed in the white Paper p175. The array object Arrays.hashcod () method.

  20. You can use GetClass (). GetName () to get the object's type name, each object class has a ToString method to display the data field, to achieve the effect of the auxiliary test, can be called in two ways, a.x.tostring (), Called directly through the object variable name, B. "" +x, automatically calls X.tostring, and then connects with "", in addition,. println (x), the ToString method of x is automatically called. For array objects, using static method Arrays.tostring, the author recommends adding the ToString method for each custom class to react to state field information. For multidimensional arrays, use the arrays.deeptostring () static method

  21. Super-class information can be obtained by using the Getsuperclass method.

  22. Generic Array list: The ability to automatically adjust array length when adding an array element is added, in which the diamond syntax is designed. Detailed in P181, white paper. arraylist< type name > variable name = new arraylist< can be added with type name > (); add element, variable name. Size () returns the array list capacity, variable name. Ensurecapacity (quantity), And some specific use methods are detailed in P181, white paper. One thing to note here is that the index I involved is included in 0, so you need to equate the index with the real array index when you use it. , the ToArray method can export the contents of an array list to an array.

  23. Object wrappers and auto-boxing P187 white papers, and methods that can modify numeric parameters by holder type variables, such as IntHolder types.

  24. A compatibility problem between typed array lists and the original array list, detailed in P186, white paper.

  25. The variable parameter method, detailed in P190, actually, printf receives two parameters, one is the format string, the other is the object[] array, and if there is a base type in the object[] array, it will be boxed automatically. The last parameter is a method of an array that can be redefined as a parameter method, but does not need to break existing code.

  26. Enumeration type/class, detailed in P191, can be used = = To determine whether the two enumerated type variables are the same, because both are references to the enumeration type constant address, did not create a new instance, so you can use the address to determine whether the same.

  27. The. Constant name. ToString Gets the constant name, variable =enum.valueof (enum type name. class, enumeration constant name), sets the variable to a specific enumeration constant, and each enumeration type contains the values method, which returns all the enumeration constants in the class. Note that an array of enum types is received, ordinal is a method that enumerates the type constants, and returns the value of the constant (position, starting at 0).

This article is from the "Developing_rookie" blog, make sure to keep this source http://8942041.blog.51cto.com/8932041/1629743

Java fifth to Seventh Day learning content Review--java White Paper fifth chapter

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.