473,394 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

AND and OR in Java

Hi all brothers,

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

Thanks
Oct 12 '07 #1
14 1991
JosAH
11,448 Expert 8TB
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
Oct 12 '07 #2
r035198x
13,262 8TB
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.
Oct 12 '07 #3
r035198x
13,262 8TB
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?
Oct 12 '07 #4
JosAH
11,448 Expert 8TB
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
Oct 12 '07 #5
r035198x
13,262 8TB
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?
Oct 12 '07 #6
JosAH
11,448 Expert 8TB
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
Oct 12 '07 #7
r035198x
13,262 8TB
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?
Oct 12 '07 #8
JosAH
11,448 Expert 8TB
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
Oct 12 '07 #9
r035198x
13,262 8TB
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
Expand|Select|Wrap|Line Numbers
  1. if("test") {
  2.      }
would be allowed?
and
Expand|Select|Wrap|Line Numbers
  1. boolean foo = "test";
would have a value of 0?
Oct 12 '07 #10
JosAH
11,448 Expert 8TB
So
Expand|Select|Wrap|Line Numbers
  1. if("test") {
  2.      }
would be allowed?
and
Expand|Select|Wrap|Line Numbers
  1. boolean foo = "test";
would have a value of 0?
1) The syntax in RPL is:

Expand|Select|Wrap|Line Numbers
  1. if "foo" then ... # true, so the then branch is evaluated
  2.  
2) You'd just do:

Expand|Select|Wrap|Line Numbers
  1. 'foo "test" =
  2. if foo then ... # true, so the then branch is evaluated
  3.  
Read all about it in my 'tips of the weeks' article parts! ;-)

kind regards,

Jos
Oct 12 '07 #11
r035198x
13,262 8TB
1) The syntax in RPL is:

Expand|Select|Wrap|Line Numbers
  1. if "foo" then ... # true, so the then branch is evaluated
  2.  
2) You'd just do:

Expand|Select|Wrap|Line Numbers
  1. 'foo "test" =
  2. if foo then ... # true, so the then branch is evaluated
  3.  
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.
Oct 12 '07 #12
JosAH
11,448 Expert 8TB
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.

Expand|Select|Wrap|Line Numbers
  1. 'baz 'if then "foo" else "bar" end =
  2. 42 baz
  3.  
The result is "foo"

kind regards,

Jos
Oct 12 '07 #13
r035198x
13,262 8TB
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.

Expand|Select|Wrap|Line Numbers
  1. 'baz 'if then "foo" else "bar" end =
  2. 42 baz
  3.  
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.
Oct 12 '07 #14
JosAH
11,448 Expert 8TB
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
Oct 12 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what...
1
by: ptaz | last post by:
Hi I'm trying to run a web page but I get the following error. Ca anyone please tell me a solution to this. Thanks Ptaz HTTP Status 500 - type Exception report
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
0
by: mailkhurana | last post by:
Hii , I am trying to use a type 2 driver to connect to DB2 0n AIX 5 I have a small java test to class to establish a conneciton with the db .. I am NOT using WAS or any appserver When I try to...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
12
by: Mark Fink | last post by:
I wrote a Jython class that inherits from a Java class and (thats the plan) overrides one method. Everything should stay the same. If I run this nothing happens whereas if I run the Java class it...
0
by: jaywak | last post by:
Just tried running some code on Linux (2.4.21-32.0.1.EL and Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)) and Windows XPSP2 (with Java HotSpot(TM) Client VM (build...
1
by: jaimemartin | last post by:
hello, I want to validate an xml by means of a schema (xsd). To do that first of all I´m using a SchemaFactory. The problem is that if I run the code in Windows all works fine, but If I run it in...
0
oll3i
by: oll3i | last post by:
package library.common; import java.sql.ResultSet; public interface LibraryInterface { public ResultSet getBookByAuthor(String author); public ResultSet getBookByName(String name);
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.