See "java programming thinking," notes (5-6)

  The previous chapter is now a few days before the record, the following chapter slowly released. For this month, I read this book, many of my notes read by the experience, there may be some wrong expression. If it is so, Please correct me. 

  Chapter V 

  1. Java original documents, can have more than one category, but there can be only one public category, and the name and documentation of the same name. 

  2. Running java explained when it first went classpath environment variables, these variables in the path of java explanation for these directories will go first class document root directory.    But if you use jar package, you need to document names will be added to the middle of environment variables.    If the name of the same type, it can clash, this time need to clearly specify the location category.    CLASSPATH capital needs 

  3. Java in the public, private, protect access control at the three, should be placed on every member of the definition of the front.    Whether members of this data or methods, a visit to control it at the back just a member, not as like c + +.    Java does not write access control at the three, it will use the default control authority. 

  4. Default control authority (package access): with a bag of the class can access.    Public: Any person can access the members.    Private: that in addition to this category (which includes members of this category), the other can not be visited.    Protect: base class can access method, but other types can not visit 

  5. Each document (compiled modules), there can be only one public category, but can also support a number of functions, if a file in two or more categories of the public, will compiler error.    Public needs of the name of the same name and documents, including letters to the same case.    Otherwise, the compiler will also error.    Document can be no public category, although this rare document names at this time can easily take. 

  6. Category, it is not private and protect, there are only two types of class, the public and package type.    If you do not want others to visit this class, you can structure will be set up for private functions, such people will not be able to create the object of this class, you can provide a method to create a static object.    (Note 1: Another impact of such private constructor function is similar. Then it can not be inherited. Note 2: Internal category will enable private and protected. (Some do not, the back sections to be understood)) 

  7. Visit to the control of two reasons: one is to prohibit users touch things they should not touch.    This will simplify the understanding of their category.    Class II is to be the designers, programmers do not bothered to amend class library under the premise of the internal operation mechanism. 

  Chapter VI 

  1. In the design of a basic principle.    Design for private data types.    Will be designed for public type.    Of course meet exceptional circumstances can be adjusted. 

  2. Derived class may change in the method of a base class (such as draw ()), when still need to call the base class's method, you can use super.draw () 

  3. Derived class constructor for will be automatically call the base class constructor function without parameters.    If the base class constructor is not the default (non-parametric structural function), we must use the appropriate parameters and super clear call to the corresponding base class constructor function, and the statement must be on the forefront derived class constructor function, the compiler will first implementation of base class constructor, in the implementation of the derived class constructor function. 

  4. Final has three purposes, namely for data (data), the method (method), and type (class) 

  L Final for data, when the original data type is type of data that this is a constant.    When the data type is the object reference, the reference that this is a constant, once connected to a reference object, can no longer connect to other objects.    However, the data object itself can be amended (the only one static), the final data, in a statement when the assignment data can also function in the structure assignment.    We can use in the final parameters, the reference to participate in this operation can not point to other objects 

  L Final for Method: There are two ways for the final effect, a method is locked to prohibit derived class changes, the efficiency of two reasons is that if the method is final.    So the compiler to call for the conversion of (inline)) (the compiler will automatically determine whether the ITU) 

  L Final for categories: mean that you do not inherit this class, you also not allowed other people to inherit this class.    As can not inherit this class, like all of the implicit methods into final 

  5.    In the category of the succession of initialization: first-class initialization of the static, and then the static is derived class.    Then create the object, then the original target of all types of variable initial values will be translated into all become null reference, and then call the base class constructor is called in the derived class constructor 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Recommend Articles

Comments

Leave a Reply