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

Can a vector contain heterogenous objects?

801


Can you inherit a constructor java?

807


java program with complete 4 oops concepts implemented example

2923


Can we sort arraylist in java?

777


What is meant by 'bit masking' in java?

863


Name some classes present in java.util.regex package.

799


What does yield method of the thread class do?

757


What is the use of arraylist in java?

777


Which collection is best for sorting in java?

883


Which programming language is best in future?

720


If I don't provide any arguments on the command line, then what will the value stored in the string array passed into the main() method, empty or null?

1006


How do you include a string in java?

745


What is the meaning of variables in research?

765


What is == mean?

748


What is the java virtual machine?

842