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. great material for language bugs....
View Tutorial          By: manoj kapri at 2009-11-30 00:30:13

2. Sir, can you give me an example of Isalnum in java
View Tutorial          By: Angeline at 2011-07-13 06:43:54

3. Hi Its very useful ad nice article Thanks
View Tutorial          By: Hanish at 2011-07-22 13:12:23

4. A good Article..........

Thanks!!

View Tutorial          By: Pravesh at 2011-12-08 03:34:01

5. Hi there, a nice tutorial. i wanna ask, what about
View Tutorial          By: Alfa at 2013-03-06 04:04:26

6. good understandability code
View Tutorial          By: Raja Mahendra Kumar at 2009-03-05 03:11:26

7. How to execute all these 5 files plz tell me step
View Tutorial          By: Umesh Kamankar at 2011-03-19 10:56:29

8. why have you change first name oak to java ?
View Tutorial          By: manohar patil at 2014-08-20 03:44:23

9. Thanks,It's perfect solution,I solved my probleam
View Tutorial          By: Suryaprakash Raghuwanshi at 2009-07-04 19:06:24

10. Plz send code of sending sms from java code...

View Tutorial          By: Shekh at 2014-11-27 14:18:25