Monday, June 3, 2013

Thinking in Java

Cleanup: finalization (finialize()) and garbage collection 

  1. Your object might not get garbage collected 
  2. Garbage collection is not destruction 
  3. Garbage collection is only about memory
Force garbage collection:
System.gc();

use of finalize:
protected void finalize(){
  if(some conditions)
      errorMessage;
}

Array 

int[] a; 
Random rand = new Random(47); 
a = new int[rand.nextInt(20)]; 

Inner Class

inner class and surrounding class 
public class Parcel1 { class Contents { //protected, also can be + -; private int attribute; public int method() { return 0; } }









OuterClassName.InnerClassName

Out.Inner inner = out.getInner(); 


In addition, inner classes have access rights (link) to all the elements in the enclosing class. (different from C++ which does not have links) 
done

No comments:

Post a Comment