Yahoo Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

Hashcode of Object class returns a value by converting the internal address of the object into an integer,

- sdm February 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

hm.. the question wants relation between hashcode method and equals method.

if you made a user defined class, you should override hashcode and equals methods satisfying codes below.
{{
UserDefindedClass a, b;
a = make();
b = anotherMake();
if (a.equals(b)) {
assertTrue(a.hashCode()==b.hashCode());
}
}}

- Zaphod March 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

You want to override these methods whenever you want to use your class with a Hashtable.

- Tim March 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

map collection in java requires that hashcode and equals be overridden to retrieve values from the map (using get()). public int HashCode(), public boolean Equals()

- Anonymous March 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Check this link . very nicely expained :
technologiquepanorama.wordpress.com/2009/02/12/use-of-hashcode-and-equals/

- Harshit April 25, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

One needs to override hashCode() and equals() method when one needs to use a custom class as a key into HashMap (or Hashtable). following rules apply
a) Same members must be used in both hashCode() and equals().
b) hashCode() must different values as possible for different objects, this will ensure objects are better placed in different buckets of the map.
c) If one uses different members within hashCode and equals method then when map.get(o1) will return null even after we have zeroed in on the bucket.

hashCode() is a native method which returns the address at which this object is stored in heap.hashCode() in Object returns the hexadecimal representation of the address at which this object is stored in heap. toString() returns classname + "@" + hashCode().

- Singleton July 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

if two objects are equal their hashcodes must be equal, opposite is not true though

- dhrubo August 01, 2010 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More