×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    May 2009
    Posts
    95

    Using && in J2ME...

    Hi,

    I'm totally mixed up because according to my knowledge when you use '&&' in a condition like:

    Code:
                    while ((inputStream.available() > 0) && (bufferUsed = inputStream.read(buffer)) > 0){
    It should check if the first one is true, if not it won't even check the second condition. Right ?

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Using && in J2ME...

    That's right. "&&" and "||" both perform short-circuit evaluation. For "&&", the second expression is only evaluated if the first is true. For "||", the second is only evaluated if the first is false.

    Graham.

  3. #3
    Regular Contributor
    Join Date
    May 2009
    Posts
    95

    Re: Using && in J2ME...

    That's strange because i had a code like that and the very same code with two if statements and the first one was failing on Nokia 6120classic for some reason. I was testing with the same data and everything, but still it wasn't working...

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Using && in J2ME...

    Code:
    if (a) {
        if (b) {
        }
    }
    And...

    Code:
    if ((a) && (b)) {
    }
    Will behave identically. The logic certainly cannot vary from device to device, since the semantics of "&&" are handled by the compiler, not the virtual machine.

    Graham.

Similar Threads

  1. J2ME or C++ for VoIP on Mobile
    By sandeepkumar03 in forum VoIP
    Replies: 4
    Last Post: 2009-02-02, 10:28
  2. Calling a native c or c++ application from J2ME
    By satyarajasekhar in forum Mobile Java Networking & Messaging & Security
    Replies: 5
    Last Post: 2009-01-02, 12:10
  3. J2ME or C++ for VoIP on Mobile Phone
    By sandeepkumar03 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2008-11-13, 20:14
  4. Acessing voice channel using J2ME
    By diegomello in forum VoIP
    Replies: 1
    Last Post: 2008-10-21, 15:57
  5. Can J2ME be used for sending MMS Message ?
    By seno_ap in forum Mobile Java General
    Replies: 1
    Last Post: 2006-11-24, 14:36

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×