ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
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.
 Question Submitted By :: Bose
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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
# 1
//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 ?    0 Yes 0 No
Pushpa
 
  Re: 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
# 2
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 ?    0 Yes 0 No
Murli
 
 
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
What is the difference between Abstract Class and Interface AMDOC6
static inner classes means..?  1
can you program for reverse string? IBM5
Can a lock be acquired on a class?  2
whats the diff between jsp and servlets? HCL9
What are command line arguments?  2
Can we have a abstract class withought any method? What is a purspose of this?  1
What is the difference between pageContext and page implicit objects in jsp? Merrill-Lynch6
what is difference between excute query ()and execute update ()? Symphony5
In what type of containers, Border layout is a default layout?  3
why is multiple inheritance not allowed in java? Elementus-Technologies5
Difference String and String Buffer  3
How the elements are organized in BorderLayout?  4
84. try { 85. ResourceConnection con = resourceFactory.getConnection(); 86. Results r = con.query(”GET INFO FROM CUSTOMER”); 87. info = r.getData(); 88. con.close(); 89. } catch (ResourceException re) { 90. errorLog.write(re.getMessage()); 91. } 92. return info; Which is true if a ResourceException is thrown on line 86? 1 Line 92 will not execute. 2 The connection will not be retrieved in line 85. 3 The resource connection will not be closed on line 88. 4 The enclosing method will throw an exception to its caller.  1
What is the root class for all Java classes?  4
Why can't we make jsp as a controller and action servlet in struts? TCS6
whats the life cycle of jsp Satyam2
What is compile time polymorphism? Elementus-Technologies6
How do u provide security in java  1
what is dynamic method dispatch ? Fidelity11
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com