Marker Interface in Java

Marker interface in Java is an interface with empty body. A marker interface does not contain constants or methods. Examples of marker interfaces in Java are- java.util.RandomAccess java.rmi.Remote java.io.Serializable java.lang.Cloneable If you see the code for Cloneable interface in JDK, it is as given below. public interface Cloneable { } As…

Continue reading

finalize() Method in Java

finalize() method in Java is a callback method which is called before any object is garbage collected. Table of contents What does finalize() method do finalize() method is part of Object class finalize() method is not reliable How to use finalize() method in Java finalize() method Java example Exception in…

Continue reading

Constructor in Java

Constructor in Java is a special method which is called automatically to initialize an object when the object is created. Table of contents Need for a constructor Java constructor example Rules for Constructors Types of constructors Private constructor in Java Private constructor example Need for a constructor When an object…

Continue reading

Initializer Block in Java

When you create an instance of a class, constructor is called to initialize the instance variables. An alternative to using a constructor to initialize instance variable is to use initializer block in Java. Initializer block is always executed when an instance of the class is created. General form of Initializer…

Continue reading