Java Fourth day Learning content Review--java White paper fourth chapter

Source: Internet
Author: User

  1. Java does not support destructors because it has an automatic garbage collector and does not need to manually reclaim memory or resources.

  2. The Finalize method can be added to any class that can be used to reclaim scarce resources, but the author does not advocate the use of this method because the programmer cannot determine at what point the method will be called, only that it will be called before the garbage collector.

  3. System.runfinalizersonexits This method ensures that the finalizer method is called before Java is closed, but the author does not consider it to be safe. There is an alternative approach: the Runtime.addshutdownhook method, which is described later in the white paper.

  4. Import in Java and # include in C + + may look the same, but there is an essential difference--c/c++ compiler does not have the ability to view files, but Java compilation has this function, so there is a cause and effect: so C + + needs to use # Include to include the declaration, whereas Java uses import to simply include the path to the package and then have the compiler to view the file. There is another cause and effect: so C + + does not have a # include, but in Java if you want to declare a variable, at this point if the path of the package is fully given and the class name in this package is a type, you can not use import to include the package, the program will not be wrong. The authors point out that their namespce and using two reserved words are more similar to the package and import in Java than the # include in C + +;

  5. About static import in Java, the author is ambiguous and detailed in the P136 white paper.

  6. Put the class into the package, you need to take advantage of the package+ package name, and put this statement at the beginning of the source file, otherwise this class will be placed in the default package, detailed in the white paper P137

  7. For classes, data fields, methods, and so on that do not have public and private adornments, the representation can be accessed by all methods in this package. So be sure to note that private cannot be forgotten, otherwise it will destroy the encapsulation of the class. About the package sealing mechanism detailed in the white Paper P140, you can disallow adding classes to the package.

  8. The path issue is detailed in the white Paper p141, which is temporarily skipped

  9. The comment question is detailed in the white Paper p144, which is currently a very sketchy view.

  10. Java class design should be aware of: a. Be sure to keep the data private B. Be sure to initialize the data C. Do not use too many basic types. D. The duties of a class should not be excessive E. naming

  11. The following is the fifth chapter

  12. The inherited keyword in Java is extands--a Extands B inherits from B, unlike in C + +: And all inheritance in Java is a common inheritance. Superclass--the equivalent of a superset of a class (B), a subclass--equivalent to a subset of the class (A).

  13. A method in a subclass cannot directly access a private data field in a superclass, it needs to be called through an accessor (interface function) in a superclass, if a method in a subclass violates a method in a superclass, overrides a superclass method, and if you want to use a superclass method you can take advantage of super. Method name, which differs from C + +::. Although it can be overridden, it is not possible to delete any elements (methods, data fields) in the superclass.

  14. The constructor for the Java subclass calls Super (), and as a constructor that calls the superclass, initializes the data fields declared in the superclass in the subclass, and super () must be placed at the first statement position. Here the author mentions that the method of this and super in Java is somewhat similar, for example this has two functions 1: means to hide parameter 2: constructor transfer super also has two function 1: Using the same name method of the Superclass 2: Call the superclass constructor.

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

Java fourth day learning content Review--java White paper fourth 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.