package finalize;

public class FinalizeExample {

   @Override

    protected void finalize() throws Throwable {

        System.out.println("Finalize called");

    }

     

    public static void main(String[] args) {

        for (int i = 0; i < 10000000; i++) {

            FinalizeExample f = new FinalizeExample();

        }

    }

}

 

 

 

 

 

public class GC {

    public static void main(String[] args) {

        GC gc = new GC();

        StringBuffer sb = gc.createStrings();

    }

   

    public StringBuffer createStrings() {

        StringBuffer sb1 = new StringBuffer("hello");

        StringBuffer sb2 = new StringBuffer("world");

        return sb2;

    }

}

 

 

 

 

 

package parameters;

public class Primatives {

    public static void main(String[] args) {

        int num1 = 5;

        System.out.println("Value at point 1 is "+num1);

        changeMe(num1);

        System.out.println("Value at point 3 is "+num1);         

    }

     

    private static void changeMe(int num) {

        num += 5;

        System.out.println("Value at point 2 is "+num);

    }

}

 

 

 

 

 

package parameters;

 

public class PassObject2 {

 

    public static void main(String[] args) {

        StringBuffer sb = new StringBuffer("Hello");

        System.out.println("Value at point 1 is "+sb);

        changeMe(sb);

        System.out.println("Value at point 3 is "+sb);     

    }

 

    private static void changeMe(StringBuffer sb1) {

        sb1.append(" World");

        System.out.println("Value at point 2 is "+sb1);

     }

}

 

 

 

 

package parameters;

public class PassObject3 {

    public static void main(String[] args) {

        String s = "Hello";

        System.out.println("Value at point 1 is "+s);

        changeMe(s);

        System.out.println("Value at point 3 is "+s);

    }

 

    private static void changeMe(String s) {

        s += " World";

        System.out.println("Value at point 2 is "+s);

    }

}

 

 

 

 

 

package nullexample;

 

public class NullString {

 

    public static void main(String[] args) {

        StringBuffer sb = null;

        sb.append("Hello");

    }

}

 

 

 

 

 

package nullexample;

 

public class NullString {

 

    public static void main(String[] args) {

        StringBuffer sb;

        sb.append("Hello");

    }

}