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. explanation is good but i have one doubt what is t
View Tutorial          By: sulthan at 2012-10-09 06:13:14

2. Excellent Example...... To understand the concept
View Tutorial          By: SUNNY at 2009-02-24 23:41:04

3. u hav done Nice job..
View Tutorial          By: Rakesh at 2012-10-01 16:00:14

4. I have a source code of j2ee. but i want to conver
View Tutorial          By: bangaram at 2011-06-07 09:28:45

5. You can save a file from the content of the input.
View Tutorial          By: anne at 2011-11-22 10:50:10

6. I am not found a J2ME file for playing a audio pla
View Tutorial          By: S.M. ASHIQUER RAHMAN at 2008-11-22 22:33:43

7. Hi Sir...
sir i am a student and I am worki

View Tutorial          By: shanthi at 2013-03-22 11:01:15

8. nice
View Tutorial          By: ravi at 2010-11-26 02:46:56

9. Sorry Actually i used previous version of comm.jar
View Tutorial          By: A.Balaji at 2010-09-15 02:44:55

10. any one can send serial port communication using n
View Tutorial          By: prakash at 2013-07-01 15:44:48