System.out.println(S1==S2)????????

/* My question is not regrading to equals or == when i compile and run following code it shows outputS1 equals S2 true false where is S1==S2 string goes it should display following outputS1 equals S2 true S1 == S2 false

what im thinking in second case it first evalute and execute first == state ment then try to compare boolean value with String i.e s2 is compare against result of s3==s4 . but whatever case problem is that it is ignoring String in" "

Hi yogesh.The arithmetic operators have higher precedence than comparison operators.So when u say 1) String s4 is getting added to the string "s1==s2" 2) String s1 is getting added to the result of step 1 above. Thus we have a new String which is "HelloS1==S2Hello".This String is compared with String s1.Predictably,this gives false , which is a boolean value.Since == cannot be applied to a boolean value,hence the exception. I hope i have been clear enough. ------------------ Come on in !! Drinks are on the house in the Big Moose Saloon !!

Udayan Naik<BR>Sun Certified Programmer for the Java 2 Platform

yogesh sood
Ranch Hand

Joined: Aug 31, 2000
Posts: 108

posted Nov 02, 2000 23:35:00

0

thanks to all of u i got it very nicely

Udayan Naik
Ranch Hand

Joined: Oct 18, 2000
Posts: 135

posted Nov 05, 2000 21:42:00

0

Mr Gautam Shah, I understand your point.But my point is that first solve the basic question ie. operator precedence.If the user wants a intro. on compiler mechanics , i'm sure he will ask for it.Firstly let him clearly understand operator precedence.Compiler quirks and dynamics can come later. And i'm sure that we all have some pieces of code that can put the best of Java professionals into a tizzy.

------------------ Come on in !! Drinks are on the house in the Big Moose Saloon !!