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.
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值