Comment on Tutorial - equals( ) Versus == in Java By Mashoud



Comment Added by : saurabh

Comment Added at : 2009-07-30 15:19:49

Comment on Tutorial : equals( ) Versus == in Java By Mashoud
There is no need to fight. ...whatever ku is saying is correct and what arpita experienced is also correct.
Ku will be correct if I say
String s1 = "Hello";
String s2 = "Hello";
the big difference is here I am not explicitly creating a new object , instead if I had used String s2 = new String ("Hello") just like in thread 1 then I will get s1 == s2 not true which arpita got. Arpita if you try s2 = "Hello" in your program you may get true (depends on your jvm)

One more thing what ku said is JVM specific, a particular JVM can choose to maintain String pool while other may not.
String API just guarantees that equals() will work as intended but not == .


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. Thank you for the code. Could you please send me c
View Tutorial          By: Ying at 2009-08-17 13:58:16

2. it works! thanks! :D
however I would like t

View Tutorial          By: john at 2012-11-15 10:50:33

3. actually very good site. I learned more & more
View Tutorial          By: shiranthi at 2012-07-12 12:18:38

4. Thanks it helped to understand but error occurred
View Tutorial          By: Maya at 2010-11-17 22:08:10

5. "Invalid Password at the jsp bcos RuntimeExce
View Tutorial          By: Ogah I. G at 2013-01-08 16:44:54

6. i have clear that notify and wait
but where

View Tutorial          By: pp at 2009-06-29 06:12:13

7. the way of explanation is really good. there is a
View Tutorial          By: Arul at 2009-01-09 00:13:46

8. sir i am mca student. i can choose my flatform is
View Tutorial          By: sridevi at 2012-06-06 10:21:39

9. Dear Friend,
Your programs is like the one

View Tutorial          By: thomas at 2009-11-02 00:38:18

10. sir i need some simple example of jdbc i cannot un
View Tutorial          By: Velkumar.s at 2013-05-15 07:08:37