Note of 《thinking in java》5

5. Hiding the Implementation

  1. A primary consideration in object-oriented design is "separating the things that change from the things that stay the same."
  2. There can be only one public class in each compilation unit, otherwise the compiler will complain.
  3. A working program is a bunch of .class files, which can be packaged and compressed into a Java ARchive(JAR) file(using Java's jar archiver).
  4. The Java interpreter finds the environment variable CLASSPATH(set via the operating system, and sometimes by the installation program that installs Java or a Java-based tool on your machine).
  5. The CLASSPATH can contain a number of alternative search paths.
  6. When the compiler encounter the import statement for the current library, it begins searching at the directories specified by CLASSPATH.
  7. All objects can easily be force into String representation by putting them in a String expression.
  8. Don't make the mistake of thinking that Java will always look at the current directory as one of the starting points for searching. If you don't have a '.' as one of the paths in your CLASSPATH, Java won't look there.
  9. You might not initially think you'll use the private keyword often since it's tolerate to get away without it. (This is a distinct contrast with C++.)
  10. A reference to an object is private inside a class doesn't mean that some other object can't have a public reference to the same object.
  11. Since the default constructor is the only one defined, and it's private, it will prevent inheritance of this class.
  12. Sometimes the creator of the base class would like to take a particular member and grant access to derived classes but not the world in general. That's what protected does.
  13. Classes browsers have become an expected part of any good Java development tool.
  14. Note that a class can not be private(that would make it accessable to no one but the class) or protected.
  15. If you don't want anyone else to have access to that class, you can make all the constructors private, thereby preventing anyone but you, inside a static member of the class, from creating an object of that class.
  16. Actually, an inner class can be private or protected, but that's a special case.
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章