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.

Answers were Sorted based on User's Feedback



I have one POJO class(Java bean class), it has two variables for that it has setters and getters. ..

Answer / murli

override equals method from object class and have the comparison logic inside that.Also override hashcode method..
Now pBeanOne.equals(pBeanTwo) will give you the result

Is This Answer Correct ?    13 Yes 0 No

I have one POJO class(Java bean class), it has two variables for that it has setters and getters. ..

Answer / 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

More Core Java Interview Questions

how jvm allocates memory for stack?

1 Answers   HP, Ramco,


What does localhost mean?

0 Answers  


What is meant by design patterns?

0 Answers  


3) Suppose you are a very rich person, having 50 rooms and you have lost the key for one of the room's. How effectively you can find this key? (Qs2 and Qs3 are related)

3 Answers   RBS,


Name the method that is used to set a TextComponent to the read-only state?

1 Answers  


What do you mean by byte code?

0 Answers  


Is java 11 paid version?

0 Answers  


What is cloneable interface?

8 Answers  


JVM is platform independent or depeneded?

7 Answers  


Which method will get invoked first in a stand alone application?

1 Answers  


what is mean by overriding in which situation we wil use?

5 Answers   Atlas Systems, CSC, DCPL,


What is variable argument in java?

0 Answers  


Categories