AND and OR in Java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hhhhhhhh
    New Member
    • Oct 2007
    • 12

    AND and OR in Java

    Hi all brothers,

    Please give me some idea how to use AND and OR in java.

    Thanks
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by hhhhhhhh
    Hi all brothers,

    Please give me some idea how to use AND and OR in java.

    Thanks
    There are no such things as AND and OR in Java. There are &, &&, | and || instead
    and they're binary operators.

    The & and | operators operate on both any integral domain where they serve the
    same purpose as 'bitwise-and' and 'bitwise-or' operators and the boolean domain.

    The && and || operators operate on just the boolean domain and don't evaluate
    the right operand when the answer can be 'concluded' from the left operand.

    kind regards,

    Jos

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by hhhhhhhh
      Hi all brothers,

      Please give me some idea how to use AND and OR in java.

      Thanks
      Those are neither Java keywords nor valid operators.
      If you want the correct Java operators for AND and OR then just google them or refer to a Java textbook.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by JosAH
        There are no such things as AND and OR in Java. There are &, &&, | and || instead
        and they're binary operators.

        The & and | operators operate on both any integral domain where they serve the
        same purpose as 'bitwise-and' and 'bitwise-or' operators and the boolean domain.

        The && and || operators operate on just the boolean domain and don't evaluate
        the right operand when the answer can be 'concluded' from the left operand.

        kind regards,

        Jos
        My, my. What's the occasion?

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by r035198x
          My, my. What's the occasion?
          What occasion? I was playing with my RPL language and realized that doubling
          the int and boolean domains would never have been necessary if there were no
          boolean domain (as in C). My fingers were still in their typing mode so that's why. ;-)

          kind regards,

          Jos

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by JosAH
            What occasion? I was playing with my RPL language and realized that doubling
            the int and boolean domains would never have been necessary if there were no
            boolean domain (as in C). My fingers were still in their typing mode so that's why. ;-)

            kind regards,

            Jos
            So are you going to go the C no boolean domain way?

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by r035198x
              So are you going to go the C no boolean domain way?
              yup, every other domain can double as a boolean domain if you just simply
              define it; e.g. the String "foo" can be defined as true because the String contains
              characters; the String "" can be defined to be false because it doesn't contain any
              characters. It's just a matter of definition that takes away all those explicit conversion
              code. Gosling eat your heart out ;-)

              kind regards,

              Jos

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by JosAH
                yup, every other domain can double as a boolean domain if you just simply
                define it; e.g. the String "foo" can be defined as true because the String contains
                characters; the String "" can be defined to be false because it doesn't contain any
                characters. It's just a matter of definition that takes away all those explicit conversion
                code. Gosling eat your heart out ;-)

                kind regards,

                Jos
                What will be the size of a boolean then?

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by r035198x
                  What will be the size of a boolean then?
                  For an explicit boolean value (if needed) the domain and size are ints 0 and 1 for
                  false and true respectively.

                  kind regards,

                  Jos

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Originally posted by JosAH
                    For an explicit boolean value (if needed) the domain and size are ints 0 and 1 for
                    false and true respectively.

                    kind regards,

                    Jos
                    So [CODE=rpl]if("test") {
                    }[/CODE]
                    would be allowed?
                    and
                    [CODE=rpl]boolean foo = "test";[/CODE]

                    would have a value of 0?

                    Comment

                    • JosAH
                      Recognized Expert MVP
                      • Mar 2007
                      • 11453

                      #11
                      Originally posted by r035198x
                      So [CODE=rpl]if("test") {
                      }[/CODE]
                      would be allowed?
                      and
                      [CODE=rpl]boolean foo = "test";[/CODE]

                      would have a value of 0?
                      1) The syntax in RPL is:

                      Code:
                      if "foo" then ... # true, so the then branch is evaluated
                      2) You'd just do:

                      Code:
                      'foo "test" =
                      if foo then ... # true, so the then branch is evaluated
                      Read all about it in my 'tips of the weeks' article parts! ;-)

                      kind regards,

                      Jos

                      Comment

                      • r035198x
                        MVP
                        • Sep 2006
                        • 13225

                        #12
                        Originally posted by JosAH
                        1) The syntax in RPL is:

                        Code:
                        if "foo" then ... # true, so the then branch is evaluated
                        2) You'd just do:

                        Code:
                        'foo "test" =
                        if foo then ... # true, so the then branch is evaluated
                        Read all about it in my 'tips of the weeks' article parts! ;-)

                        kind regards,

                        Jos
                        Hey, I'm still getting to grips with that syntax. It's hard enough switching between Java, C++, and C#. Now RPL. I'm really beginning to get it though. Very soon I'll be able to contribute.

                        Comment

                        • JosAH
                          Recognized Expert MVP
                          • Mar 2007
                          • 11453

                          #13
                          Originally posted by r035198x
                          Hey, I'm still getting to grips with that syntax. It's hard enough switching between Java, C++, and C#. Now RPL. I'm really beginning to get it though. Very soon I'll be able to contribute.
                          Good; it's great to know that at least two persons are interested (I'm interested
                          myself too ;-) RPL is very much unlike the imperative way of thinking, OO or not.

                          RPL simply 'evaluates' objects from left to right; always. Even language elements
                          (there are no language elements, just RPL objects) can be objects that can be
                          evaluated and diddled with. e.g.

                          Code:
                          'baz 'if then "foo" else "bar" end =
                          42 baz
                          The result is "foo"

                          kind regards,

                          Jos

                          Comment

                          • r035198x
                            MVP
                            • Sep 2006
                            • 13225

                            #14
                            Originally posted by JosAH
                            Good; it's great to know that at least two persons are interested (I'm interested
                            myself too ;-) RPL is very much unlike the imperative way of thinking, OO or not.

                            RPL simply 'evaluates' objects from left to right; always. Even language elements
                            (there are no language elements, just RPL objects) can be objects that can be
                            evaluated and diddled with. e.g.

                            Code:
                            'baz 'if then "foo" else "bar" end =
                            42 baz
                            The result is "foo"

                            kind regards,

                            Jos
                            That's the part I'm still coming to grips with. I intend to dissect it all this weekend and see if I can come up with something about that linear algebra support.

                            Comment

                            • JosAH
                              Recognized Expert MVP
                              • Mar 2007
                              • 11453

                              #15
                              Originally posted by r035198x
                              That's the part I'm still coming to grips with. I intend to dissect it all this weekend and see if I can come up with something about that linear algebra support.
                              RPL evaluates everything from left to right; no exception to the rule, so in Java:
                              "a= b" has its equivalent in RPL as "a b =" but since everything is *evaluated*
                              you have to block evaluation in RPL as "'a 'b =".

                              As I wrote: Read all about it in the RPL article series! ;-)

                              kind regards,

                              Jos

                              Comment

                              Working...