jQuery in Action, 2nd edition*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doesn't print the statement in System.out.println Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doesn Watch "doesn New topic
Author

doesn't print the statement in System.out.println

Raju Sri
Ranch Hand

Joined: Mar 10, 2004
Posts: 108
Hi all,
Can any body tell me why the following code doesn't print "TO JAVA: false".
--------------------------
String h1="hello";
String h2=new String("hello");
System.out.println("WELCOME");
System.out.println("TO JAVA:"+h1 == h2);
System.out.println("CERTIFICATION");
----------------------------------
I thought the program should print like below
WELCOME
TO JAVA:false
CERTIFICATION
But when I run the code it is not printing "TO JAVA" statment .
Thanks in advance
Raju


SCJP 1.4<br />SCWCD 1.4<br />SCBCD 1.3<br />SCDJWS 1.4
Vijay Pawar
Greenhorn

Joined: Sep 04, 2003
Posts: 26
Dear shrini,
The rule is :
Operand 1 + Operand 2
If Operand 1 is a String then + will behave as concatination operator
and result will be a String
"To JAVA:" + h1 == h2 will be executed as
"To Java: hello" == h2
and the result u know is false
Bye
Jughead
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: doesn't print the statement in System.out.println
 
Similar Threads
Hash Code from Dan's Mock Exam
String is not working as i supposed it to work
equals and hashcode question
Infinite while loop
HashMap in HashMap Doubts