Professional Documents
Culture Documents
Reflection API
==============
package in.ashokit;
package in.ashokit;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
}
// Accessing private variable outside of the class using Reflection API
package in.ashokit;
package in.ashokit;
import java.lang.reflect.Field;
package in.ashokit;
import java.lang.reflect.Method;
public class Demo {
method.invoke(obj, null);
}
}
-> If we give wrong class name in Class.forName (" ") then we will get
ClassNotFoundException
-> NoClassDefFoundError will occur if jvm not able to find .class file of
particular class to load
==================
Garbage Collection
==================
package in.ashokit;
// Object created
Student s1 = new Student();
System.gc();
=> When we assign s1=null then s1 become un-referenced object and it is elgible for
GC
=> When GC identify un-referenced obj then it will call finalize ( ) method and it
will remove that object from HEAP area (memory clean up)
========================
How to invoke GC in java?
========================
System.gc();
Runtime.getRuntime().gc();
Note: Even if we call above methods there is no gaurantee that JVM will start GC
immediatley.
GC execution process will be managed by JVM only.
===============================
How GC works internally in JVM ?
===============================
-> When GC starts it will trigger STOP THE WORLD (all running threads will be
stopped for few milli secs)
-> GC will go to JVM Heap area and it will identify un-referenced objects and it
will mark them for sweep.
-> After sweeping completed memory holes will be created in Heap area to clear that
GC will perform Compaction (it will adjust memory holes).
-> After Compaction, GC will give signal to JVM to continue the execution.
Note: GC process will slow down our program execution hence Sun Microsystem didn't
give the chance for programmers to perform Garbage Collection. It will be managed
by JVM.
9 AM - 11 AM IST : Online
Generics
Inner Classes
Enums
Class Loaders