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. im taking hard time in doing programming
View Tutorial          By: joshua louis sumalinog at 2014-12-11 03:26:46

2. Good explanation, Thanks.
View Tutorial          By: bram at 2011-05-06 03:37:54

3. hiii
i m doing my final year project on sms

View Tutorial          By: jiya at 2010-10-21 07:58:24

4. Hi,
I have problem of calling javascript fu

View Tutorial          By: Shakti Prasad Priyakumar at 2008-06-06 06:11:52

5. I've been satisfied with your tutorial site. Since
View Tutorial          By: Mark Harold F. Manguino at 2008-08-06 05:00:54

6. can you send me comm.jar required for this project
View Tutorial          By: gayatri at 2013-03-19 09:53:35

7. its great!!!!
View Tutorial          By: safrgdg at 2015-02-12 10:10:07

8. hi,
How to create certificate from https://

View Tutorial          By: CN Balu Ramesh at 2011-07-19 08:38:31

9. can i also get the variable description for this p
View Tutorial          By: Maya Rao at 2013-10-04 06:06:00

10. when i am trying to compile your program one error
View Tutorial          By: anindya at 2011-11-23 03:00:49