I heared rules of JavaBean, in which first and main rule is , for every JavaBean class explicitly programmer should provide public default constructor . Please can anyone explain why do we need to provide default constructor for JavaBean
UPDATE :
Please explain clearly, why jvm will not provide default constructor for JavaBeans and how jvm reacts on providing default constructor
You make a constructor public if you want the class to be instantiated from any where. You make a constructor protected if you want the class to be inherited and its inherited classes be instantiated.
JavaBeans is a portable, platform-independent model written in Java Programming Language. Its components are referred to as beans. In simple terms, JavaBeans are classes which encapsulate several objects into a single object. It helps in accessing these object from multiple places.
A constructor is a special member function of a class which initializes objects of a class. In C++, constructor is automatically called when object of a class is created. By default, constructors are defined in public section of class.
JavaBeans are classes that encapsulate many objects into a single object (the bean). It is a java class that should follow following conventions: Must implement Serializable. It should have a public no-arg constructor. All properties in java bean must be private with public getters and setter methods.
I heared rules of JavaBean, in which first and main rule is , for every JavaBean class explicitly programmer should provide public default constructor . Please can anyone explain why do we need to provide default constructor for JavaBean
JavaBean instances are created by reflective calls to the no-arg constructor. So there has to be such a constructor.
Please explain clearly, why jvm will not provide default constructor for JavaBeans and how jvm reacts on providing default constructor
The jvm will provide a default constructor for a JavaBean if you have explicitly provided no constructors. If you do provide a constructor, you must provide a no-arg constructor besides any that you define with parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With