File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes OUTPUT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "OUTPUT" Watch "OUTPUT" New topic
Author

OUTPUT

shruti patel
Ranch Hand

Joined: Mar 10, 2008
Posts: 52


Output is "Not Hello World".. please explain the output

[edit]Add code tags. CR[/edit]
[ August 14, 2008: Message edited by: Campbell Ritchie ]
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3166
    
  10
Don't use == to compare Strings. Use the String.equals method. Search the forum for the reasons why. It's been explained many times.

Actually having just re-read your post, you may have been wondering why x==y returned true while z==y returned false. If that's the case you need to search the forum (or read the Java language Specification) for an explanation of the string pool.
[ August 14, 2008: Message edited by: Joanne Neal ]

Joanne
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36465
    
  15
Please Use Code Tags when posting code; I have added them so you can see how much easier the code is to read. And also "OUTPUT" hardly tells people what the thread is about. Please read those two FAQs and also this one.
Guido Sautter
Ranch Hand

Joined: Dec 22, 2004
Posts: 142
In 'String x = "Java";', '"Java"' is a compile time constant, thus the String pool gets into action, resulting in x and y atually refering to the same object, not only to Strings that are equal. Therefore, x == y is true.

In 'String z = new String("Java");' in contrast, a new String object is created, which is not the same as the one referenced by x and y. Consequently, x == z is false.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OUTPUT
 
Similar Threads
explain this ...please
question about properties and command line arguements
Uniqueness of objects
explain this ...please
System.out.println confusion with the quotation marks and + sign