Note of 《thinking in java》4

4. Initialization & Cleanup

  1. If Tree(int) is your only constructor, then the compilor won't let you create a Tree object any other way.
  2. Each overloaded method must take a unique list of argument types.
  3. char is promoted to int since it doesn't find an exact match.
  4. If you create a class that has no constructors, the compiler will automatically create a default constructor for you.
  5. Some people will obsessively put "this" in front of every method call and field reference, arguing that it makes it "clear and more explicit." Don't do it. There's a reason that we use high-level languages: they do things for us.
  6. While you can call one constructor using "this", you cannot call two.
  7. The construtor using "this" must be the first thing you do, or you'll get a compiler error message.
  8. The compilor won't let you call a constructor from inside any method other than a constructor.
  9. Java provides a method called finalize() that you can define for your class.
  10. Remember: First, your object might not get garbage collected; Second, garbage collection is not destruction; Third, garbage collection is only about memory.
  11. You might find that the storage for an object never gets released because your program never nears the point of running out of storage.
  12. It would seem that finalize() is in place because of the possibility that you'll do something C-like by allocating memory using a mechanism other than the normal one in Java.
  13. Finalize() is useful for obscure memory cleanup that most programmers will never use.
  14. The System.gc() is used to force finalization.
  15. Allocating storage for heap objects in Java can be nearly as fast as creating storage on the stack in other languages.
  16. In fast schemes, garbage collection is not based on reference counting. Instead, it is based on the idea that any nondead object must ultimately be traceable back to a reference that lives either on the stack or in static storage.
  17. Mark-And-Sweep requires that the program be stopped.
  18. A JIT compiler partially or fully converts a program into native machine code so that it doesn't need to be interpreted by the JVM and thus runs much faster.
  19. When you define an object reference inside a class without initializing it to a new object, that reference is given a special value of null.
  20. One direct way of giving initial value to a member is simply to assign the value at the point you define the class(You cannot do this in C++).
  21. Within a class, the order of initialization is determined by the order that the variables are defined within the class.
  22. The order of initialization is static first, if they haven't already been initialized by a previous object creation, and then the non-static objects.
  23. The default behavior of print out a class is to print the class name and address of the object.
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章