Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

Child question + operators confusion

Thread view: 
cliveswan@yahoo.co.uk - 18 Apr 2007 16:16 GMT
Hi All,

Eventually managed to get the operators working, well sort of.
I still do not understand the 'logic' bit.

Trying to get an if ..else to work, any help appreciated.

/// This line does not work??
// I do not understand why

String basem = ("BB");
String grd   = "GG";
String spfy  = "99";

if ( page9.getEntryFloorToDwelling() != basem &&
page9.getEntryFloorToDwelling() != grd &&
page9.getEntryFloorToDwelling() != spfy ){
validationResultPage9.addError("EntryFloorToDwelling", "Entry floor");
}

///This line does work (horray)
if ( page9.getEntryFloorToDwelling() == " " ) {
validationResultPage9.addError("EntryFloorToDwelling", "Entry floor");
}
Eric Sosman - 18 Apr 2007 16:43 GMT
cliveswan@yahoo.co.uk wrote On 04/18/07 11:16,:
> Hi All,
>
[quoted text clipped - 11 lines]
>
> if ( page9.getEntryFloorToDwelling() != basem &&

   This test asks the question: "Is the String object
returned by the method the exact same String object that
basem refers to?"  The question you should be asking
is instead: "Does the String object returned by the
method have the same content as the String object that
basem refers to?"  For the latter question, use the
.equals() method of the String class.

   (How can two Strings have the same content and yet
not be the same String?  Easy: My wallet contains ten
rubles and your wallet contains ten rubles, yet they
are different wallets.  If you think not, send me your
wallet -- which is, of course, my wallet!)

> page9.getEntryFloorToDwelling() != grd &&
> page9.getEntryFloorToDwelling() != spfy ){
[quoted text clipped - 5 lines]
> validationResultPage9.addError("EntryFloorToDwelling", "Entry floor");
> }

   You only think this line "works" because you haven't
tested it adequately.

   Clive, it seems to me -- no offense intended -- that
you should spend more time with a Java textbook than you
have spent thus far.  The questions you ask suggest that
you have not yet even grasped the basics of the language,
much less mastered them.  Usenet is not a good vehicle
for wholesale inculcation of basic knowledge, so I suggest
you try to learn the ABC's from a more effective source.
Come back to Usenet when you are puzzled by a particular
point in your studies, but don't use it as a substitute
for study.

Signature

Eric.Sosman@sun.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.