Java Third Day Learning content Review--java White paper, chapter Fourth

Source: Internet
Author: User

  1. Java object-oriented programming is used to noun understanding: object identity = = Variable name of an instance, object behavior = = Method of a class, object state = = The data field in the class (strictly speaking, can change the data field);

  2. Relationship between classes: Use_a,has_a,is_a three types

  3. The math class in Java is a bit special, it encapsulates functionality and doesn't involve data fields, so you don't have to hide the data

  4. The object variable name in Java is more like a pointer (like), after declaring an object instance, you must construct the object with new and then use = to link the two, or you can connect two different object variables with =, but you need to be aware that, like pointer assignment, two variables will share the same object instance from this point. The object variable does not contain an object instance, but instead refers to an object instance that explicitly sets the object variable to null to indicate that the object variable does not refer to any object instance, noting that the local (object) variable is not automatically initialized and needs to pass new or null (must lowercase) Assign a value to it

  5. Object variables in Java are all placed in the heap, and when one object contains another object variable, that object contains a pointer to another heap object.

  6. Deep-Copy objects in Java must take advantage of the Clone method

  7. The date class in Java is used to represent a point-in-time Gregoriangalendar class used to represent a calendar, and the date class provides before, after methods for comparing points of time, as well as methods such as Getday, but the author does not advocate the use of

  8. Change method: Methods for modifying Class object data fields

  9. Accessor methods: Only methods that read the data fields of the class object are syntactically indistinguishable from the former

  10. In the same source file, only one public class is allowed to load the main method, When compiled, the corresponding. class file is created for all classes in the source file, and then the class name of the main method is given to the bytecode interpreter to start, but the main method can be included in other classes so that the unit test can be selected by the IDE, and then the target class is tested, and then main in the target class will play a starting role.

  11. For a Variant for loop, it is found that the modification of the integer array in the loop block is not saved, but if it is the object, it will retain the modification marks.

  12. Note that the constructor is not a return value

  13. Here is a causal relationship: because all objects in Java are placed in the heap, they are created with new, which differs from C + +

  14. A variable with the same name as the data field cannot be declared in the constructor in Java, although no error is made.

  15. All methods in Java must be defined inside the class (shell classes), but this does not mean that all methods are inline.

  16. Attention to accessor methods: accessor methods should not directly return the object of the State field (data field), because the receiving variable will share memory with this object, so that the object can be indirectly modified through the receive variable (although private) should do is to return a copy of this object, here using the. Clone method;

  17. Access to class problem: A method of a class can access data fields in all instances of this class of objects. Instead of a data field in a particular object instance. different from C + +

  18. If the static class is stored in this type of data, all object instances of this class will share this data, referenced by the class name. The reference is used to emphasize that this data is a direct class domain that is not a special object instance, and a static constant type can make public variables in a class safe.

  19. Although it is theoretically impossible to modify a static constant, if the SetOut method can be used to break this convention, the principle is that this method is a local method that bypasses the Java implementation

  20. For static methods: Object instances are not required, directly through the class name. Call, there is a cause and effect: so you cannot access the data field in the object instance, there is a special case: unless there is static data in the data field in the object instance, the static method can still access this data. Like static variables in the same class, calling a static method is recommended to call directly using the name of the classes to emphasize that they do not depend on object instances, which is the purpose of static methods.

  21. Summary of 20: Requirements for using static methods: 1. Data fields that do not have access to the instance. 2. Concession, access only the static domain in the data domain

  22. Here's a method: Factory method.

  23. There is only one form of delivery for parameters in Java: Passing by value (copying first and then passing the copied value). So there is a cause and effect: So the parameters of the method if it is a basic type, then it will not be modified, but there is a seemingly special case but it is actually reasonable situation: if the parameter of the method is an instance object, you can implement the modification of its data field, The reason for this is that the object instance itself is a pointer (equivalent) to the existence of a reference, so even if it is copied, the result is a reference, and the two variables share a memory area at the same time, so the modification of this memory area in the method is valid

  24. Note that in Java, the default initialization for a domain (the data field in an object instance, or a higher layer: A variable stored in a heap) can be initialized to 0,boolean default initialization to False, the object defaults to NULL, but the local variable is not initialized by default. And the author does not advocate the use of default initialization because it affects the readability of the program. At this point, it is found that the domain mentioned in the white Paper should have a common feature that is stored on the heap, such as an array, will also be initialized by default, because the array is actually equivalent to a pointer =new, so it should be stored in the heap, and then it is initialized by default. Will all data stored in the heap be initialized by default?

  25. Variables in a data field in a class in Java can be directly initialized, unlike C + +, and, of course, by constructors. Also, Java uses the method when it is initialized directly. Detailed with white Paper P128 page. It also involves initializing block/static initialization blocks, as well as multi-invocation of constructors .... Here is a mess, really use the time to ponder. The white Paper P131, the content is detailed.

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

Java Third Day Learning content Review--java White paper, chapter Fourth

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.