Java does not support destructors because it has an automatic garbage collector and does not need to manually reclaim memory or resources.
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.
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.
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 + +;
About static import in Java, the author is ambiguous and detailed in the P136 white paper.
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
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.
The path issue is detailed in the white Paper p141, which is temporarily skipped
The comment question is detailed in the white Paper p144, which is currently a very sketchy view.
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
The following is the fifth chapter
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).
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.
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