What is bean in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is bean in java?

17th Jul 2017, 6:12 PM
SubramaniB
SubramaniB - avatar
7 Answers
+ 2
PersonBean pb = new PersonBean(); pb.setFirstName("Subramani"); pb.setLastName("B");
18th Jul 2017, 3:52 AM
PiGuy Harris
PiGuy Harris - avatar
+ 4
A Java Bean is just a simple class that implements the serializable interface has only a default or no argument constructor, has properties that may or may not be changed (i.e. read-write, read-only, write-only), its methods are just getters and setters and begin with get, set, or is. Example: package com.sololearn; public class PersonBean implements java.io.Serializable { private String firstName = null; private String lastName = null; private int age = 0; private int height = 0; private boolean married = false; public PersonBean() { } public String getFirstName(){ return firstName; } public String getLastName(){ return lastName; } public int getAge(){ return age; } public int getHeight() { return height; } public boolean isMarried() { return married; } public void setFirstName(String firstName){ this.firstName = firstName; } public void setLastName(String lastName){ this.lastName = lastName; } public void setAge(Integer age){ this.age = age; } public void setHeight(Integer height) { this.height = height; } public void setMarried(boolean married) { this.married = married; } } Java Beans are used to get, store, save (serializable), and transfer data. They are highly reusable from one project to the next.
17th Jul 2017, 7:23 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
bean
17th Jul 2017, 6:39 PM
S C
+ 1
what
17th Jul 2017, 6:49 PM
PiGuy Harris
PiGuy Harris - avatar
+ 1
thanks..
18th Jul 2017, 3:33 AM
SubramaniB
SubramaniB - avatar
0
do you know?
17th Jul 2017, 6:40 PM
SubramaniB
SubramaniB - avatar
0
can you tell, how to access from another class. simple example pls
18th Jul 2017, 3:36 AM
SubramaniB
SubramaniB - avatar