a) true | true && false
result is: false
b) true || true && false
result is: true
Why is a false while b is true?!
Thanks in advance,
Stefanie
There are some languages which are built on a single core concept from
which most if not all of the language features can be derived or at
least understood, Java is not one of these languages, nor are most of
the languages in general widespread use today.
Other languages you may want to look at are RUBY - which attempts an
'english - like' grammatical structure for its components.
I recommend this rather unorthodox but very readable guide to Ruby
http://poignantguide.net/ruby/
SMALLTALK an 'ancient' object-oriented language (but still in use)
which takes the approach that 'everything is an object' - even the
source code.
J
http://www.jsoftware.com/ a complex but highly efficient language
with a very strict / formal grammatical system.
Lisp - everything is a list & everything can be done by recursion.
Also as I mention in the list below it is simply not good practice to
mix Bitwise and Boolean operators in the same expression, just because
you can, does not mean you should.
To summarize the other responses & to add my own:
1. Accept that it is this way because that is how the language is
defined,
etymology (the history and evolution of words) is an interesting
topic but best applied to human languages rather than computer
programming languages.
2. Read the Java Language Specification:
http://java.sun.com/docs/books/jls/index.html
- available as HTML or PDF see section 15.22
3. And I think most important of all: Do Not Mix Boolean Operators and
Bitwise Operators in the Same Expression.
Programming languages are tools to get a job done.
If you want to do this, learn the rules of the language and use it
effectively.
If you want to understand boolean logic or computer language design
you need to study computer science (somewhere that teaches you more
than just how to program).