4. Initialization & Cleanup
- If Tree(int) is your only constructor, then the compilor won't let you create a Tree object any other way.
- Each overloaded method must take a unique list of argument types.
- char is promoted to int since it doesn't find an exact match.
- If you create a class that has no constructors, the compiler will automatically create a default constructor for you.
- 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.
- While you can call one constructor using "this", you cannot call two.
- The construtor using "this" must be the first thing you do, or you'll get a compiler error message.
- The compilor won't let you call a constructor from inside any method other than a constructor.
- Java provides a method called finalize() that you can define for your class.
- Remember: First, your object might not get garbage collected; Second, garbage collection is not destruction; Third, garbage collection is only about memory.
- You might find that the storage for an object never gets released because your program never nears the point of running out of storage.
- 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.
- Finalize() is useful for obscure memory cleanup that most programmers will never use.
- The System.gc() is used to force finalization.
- Allocating storage for heap objects in Java can be nearly as fast as creating storage on the stack in other languages.
- 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.
- Mark-And-Sweep requires that the program be stopped.
- 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.
- 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.
- 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++).
- Within a class, the order of initialization is determined by the order that the variables are defined within the class.
- 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.
- The default behavior of print out a class is to print the class name and address of the object.