ram chandra

Greenhorn
+ Follow
since Mar 14, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by ram chandra

Hi All,

I have been working in a MNC in Bangalore for the last 18 months. Over these period I am working for a retail client and our project is on middlewear. I trained on JAVA initially and then I am working only on oracle SOA now. I worked on development side for BPEL,ESB,Oracle Data Integrator. I Also worked on production support for Oracle Application Server ( applying the patches, maintaining clusters etc. ) . I also completed SCJP. Am I going the right way ? ( Is it safer to choose SOA at initial stages of the career ? )

Thanks,
Ramesh
15 years ago
Ivan Ivanic
ranch hand
Member # 159041
posted Today 11:23 AM
--------------------------------------------------------------------------------
Hi Ram,
== operator looks if two references refer to same object. equals(...) and hashcode() doesn't affect it. Since you have two different objects, each created with new operator, this comparison will always return false.
--------------------

Use Real Words !!!Use Code Tags!!! Say Thanks
scjp6


Hi Ivan ...
You told that operator looks if two references refer to same object. equals(...) and hashcode() doesn't affect it . But if I dont override the hashcode

System.out.println(t1) and
System.out.println(t2) gives different values . After I override the hashcodes , then only t1 and t2 gives same values (WeirdStringFixed@3039
).
Hi,

Thanks for the reply ..

Let me clear out the things ..

1. So when you create a new object ( other than default classes like String, Integer ) , there's no way 2 objects will become equal using == method . They can be made equal using "equals" method .

2. Is it true when you override equals method you have to override hashcode ? If so why ? In the code posted above , if you remove the hashcode override , then also it gives "true' for "equals" method


Check the outputs ::
WeirdStringFixed@3039
WeirdStringFixed@3039
true
false


My doubt is why t1==t2 returning false , evenif I override the hashcode class?? I am bit confused about this fact the when I override the hashcode , and created 2 new object and print out its giving same address (WeirdStringFixed@3039) , but when i try t1==t2, its returning false . Why ?


Edit by mw: Added Code Tags.
[ May 26, 2008: Message edited by: marc weber ]