0% found this document useful (0 votes)
3 views2 pages

Understanding JavaBeans in Java

JavaBeans are reusable software components in Java that adhere to specific conventions, including implementing Serializable, having a public no-arg constructor, and encapsulating properties with private access and public getters and setters. Setter methods must be public, return void, prefixed with 'set', and take an argument, while getter methods must also be public, return a value, prefixed with 'get', and take no arguments. An example Java program demonstrates the creation and usage of a JavaBean class, 'Student', showcasing setting and getting a property value.

Uploaded by

Riteshkumar mali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Understanding JavaBeans in Java

JavaBeans are reusable software components in Java that adhere to specific conventions, including implementing Serializable, having a public no-arg constructor, and encapsulating properties with private access and public getters and setters. Setter methods must be public, return void, prefixed with 'set', and take an argument, while getter methods must also be public, return a value, prefixed with 'get', and take no arguments. An example Java program demonstrates the creation and usage of a JavaBean class, 'Student', showcasing setting and getting a property value.

Uploaded by

Riteshkumar mali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

JAVA BEANS

JavaBean is a reusable software component written in Java.


It follows certain conventions so that it can be easily used, configured, and manipulated in tools
(like IDEs or frameworks).

JavaBeans are classes that encapsulate many objects into a single object
(the bean). It is a Java class that should follow the following conventions:
1. Must implement Serializable.
2. It should have a public no-arg constructor.
3. All properties in java bean must be private with public getters and
setter methods.

Setter and Getter Methods in Java


Setter and Getter Methods in Java properties are mentioned below:
Properties for setter methods:
1. It should be public in nature.
2. The return type a should be void.
3. The setter method should be prefixed with the set.
4. It should take some argument i.e. it should not be a no-arg method.
Properties for getter methods:
1. It should be public in nature.
2. The return type should not be void i.e. according to our
requirement, return type we have to give the return type.
3. The getter method should be prefixed with get.
4. It should not take any argument.
// Java program to access JavaBean class

package geeks;

// Driver Class

public class Test {

// main function

public static void main(String args[])

// object is created

Student s = new Student();

// setting value to the object

[Link]("GFG");

[Link]([Link]());

You might also like