I have one POJO class(Java bean class), it has two
variables for that it has setters and getters. Now i have
created two objects for that class and i have set the data
for those variables through this two objects. Now question
is i want check whether those two objects have same data or
not, for this write a program? Thanks, Bose.

Answer Posted / pushpa

//This is Pojo class with two property name and email
class PojoBean {
private String name;
private String email;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}


}
// main class to test pojo object
class PojoMain
{
public static void main(String[] args)
{
//create first instance of the Pojo Class and set property
values.
PojoBean pBeanOne = new PojoBean();
pBeanOne.setName("Pushpa");
pBeanOne.setEmail("ashish@gmail.com");


//create second instance of the Pojo Class and set
property values.
PojoBean pBeanTwo = new PojoBean();
pBeanTwo.setName("ashish");
pBeanTwo.setEmail("ashish@gmail.com");

//code to check two object is having same data or not.
if(pBeanOne.getName().equals(pBeanTwo.getName())){
System.out.println("Two object is having same Name");
}
// second property email
if(pBeanOne.getEmail().equals(pBeanTwo.getEmail())){
System.out.println("Two object is having same email");
}



}
}





Is This Answer Correct ?    11 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the library functions in java?

542


What is the difference between compile-time polymorphism and runtime polymorphism?

557


Is set ordered?

535


What is the method to expand and collapse nodes in a jtree?

606


Does set allows null in java?

506






How to create a custom exception?

567


what is singleton in java?

598


Is string pool garbage collected?

545


Convert Binary tree to linked list.

584


Explain when noclassdeffounderror will be raised ?

616


What is the difference between this() and super() in java?

538


What is string and example?

553


What are the basic control structures?

494


What is int short for?

512


Explain method local inner classes ?

589