Core Java Archive
In the following example, finalize method doesn’t execute implicitly as the memory is not running low: System.gc(): System class is providing pre-defined function called gc(). gc() method invokes Garbage collector. We invoke Garbage collector explicitly …
Factory Class: These are called design pattern classes. These objects have special behavior from plain objects. We need to implement following rules to get that behavior Rules: Class is public – Object is visible to …
Singleton class Rules: Class is public – Object is visible to other objects in communication. Constructor is private – Other classes cannot instantiate directly. Every class has factory method that is static. Factory method returns …
Runtime class: It is pre-defined class. It is belongs to java.lang package. Runtime class represents Java Virtual Environment(JVM) instance. For entire java application execution, only one JVM instance will be created. It is singleton class, …
Runtime.gc(): Runtime class has non static gc() method. It is used to start garbage collector on request. Runtime object representing JVM directly. We request the JVM directly to start Garbage collector. exec(String command): Pre-defined method …
Creating Thread using Runnable: It is an interface. It contains only one specification called run() method. We need to override run method to place thread logic. The class which is implementing Runnable interface is called …
Synchronization: The concept of allowing thread sequentially when multiple threads trying to access a resource. Every application has critical section need to be synchronized. We cannot synchronize the entire object. We can synchronize only a …
Block synchronization : Synchronized block is used to lock an object for any shared resource. Scope of synchronized block is smaller than the method. Generally we synchronize methods as shown in the above discussion. Block …
wait, notify and notifyAll(): We can implement inter thread communication using these methods. wait(), notify() and notifyAll() methods are belongs to Object class. We must use these methods with synchronized context of java application. wait() …
Inner class: Define a class inside another class. Inner class is also called nested class. Inner classes clearly have two benefits one is ‘name control’ and second one is ‘access control’. Defining more than one …