About Question enthuware.ocajp.i.v7.2.932 :
Moderator: admin
About Question enthuware.ocajp.i.v7.2.932 :
This question says that the '&' operand can have integral as well as boolean operands. What integral means in this case?
Thanks
Thanks
Online
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.932 :
integral means numeric... 2 & 3. In this case, it will do a bit wise and. This should help.
Re: About Question enthuware.ocajp.i.v7.2.932 :
Thanks for the reply. These bitwise operators are in the exam too?admin wrote:integral means numeric... 2 & 3. In this case, it will do a bit wise and. This should help.
Online
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.932 :
You don't need to learn exactly how they work for the purpose of the exam. But you should know that they exist and what is the difference between && and &.
But outside the exam, every programmer should know how bit wise operations work.
HTH,
Paul.
But outside the exam, every programmer should know how bit wise operations work.
HTH,
Paul.
-
- Posts: 9
- Joined: Sun Oct 28, 2012 8:17 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.932 :
Here are two of the proposed options:
--> & can have integral as well as boolean operands.
--> && can have integer as well as boolean operands.
Shouldn't you be consistent with the use of integral and/or integer?
Thanks,
Robert
--> & can have integral as well as boolean operands.
--> && can have integer as well as boolean operands.
Shouldn't you be consistent with the use of integral and/or integer?
Thanks,
Robert
Online
HTH,
Paul.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.932 :
No, both are different options. One means integral (which includes integer) and other means just integer.gliesian wrote:Here are two of the proposed options:
--> & can have integral as well as boolean operands.
--> && can have integer as well as boolean operands.
Shouldn't you be consistent with the use of integral and/or integer?
Thanks,
Robert
HTH,
Paul.
Re: About Question enthuware.ocajp.i.v7.2.932 :
In this example, the boolean if works fine, but the integer if's do not compile
public final static void main(String[] args) {
int i = 5, x = 9;
boolean b = true, c = false;
if(6 & 8){ System.out.println("This does not compile"); }
if(i & x) { System.out.println("This does not compile either"); }
if(c & b){ System.out.println("This works fine"); }
}
How then is this used for integral types?
Thanks
public final static void main(String[] args) {
int i = 5, x = 9;
boolean b = true, c = false;
if(6 & 8){ System.out.println("This does not compile"); }
if(i & x) { System.out.println("This does not compile either"); }
if(c & b){ System.out.println("This works fine"); }
}
How then is this used for integral types?
Thanks
Online
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.932 :
When you use & for integers, the result is an integer. So the expression is valid as such but not you can't use it for an if condition because an if condition expects a boolean.
You can do: int value = i & x; or value = 6 & 8;
You can do: int value = i & x; or value = 6 & 8;
-
- Posts: 20
- Joined: Thu Dec 19, 2013 8:22 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.932 :
Thanks this is what i wantedadmin wrote:When you use & for integers, the result is an integer. So the expression is valid as such but not you can't use it for an if condition because an if condition expects a boolean.
You can do: int value = i & x; or value = 6 & 8;

-
- Posts: 16
- Joined: Wed Feb 25, 2015 8:52 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.932 :
Hi,
I am finding conflicting information about Booleans being allowed as operands for the & operator in Oracle Java books and online. In both my Java SE 7 and Java SE 8 books (both by ORACLE) that the & operator works on integral types only. In the book "Java A Beginner's Guide Sixth Edition", page 166 (Java SE 8) is the following (little found in the Java SE 7 book):
"The bitwise operators can be used on values of type long, int, short, char, or byte. Bitwise operators cannot be used on boolean, float, or double, or class types. They are called the bitwise operators because they are used to test, set, or shift the individual bits that make up a value."
Booleans are represented by true and false in Java. Can we assume that that these values are represented by 1 and 0, respectively as in C++, etc.? Exactly how is Java representing these Boolean values in memory, and how many bits are in these representation? 1, 8, 16 bits?
Thanks
I am finding conflicting information about Booleans being allowed as operands for the & operator in Oracle Java books and online. In both my Java SE 7 and Java SE 8 books (both by ORACLE) that the & operator works on integral types only. In the book "Java A Beginner's Guide Sixth Edition", page 166 (Java SE 8) is the following (little found in the Java SE 7 book):
"The bitwise operators can be used on values of type long, int, short, char, or byte. Bitwise operators cannot be used on boolean, float, or double, or class types. They are called the bitwise operators because they are used to test, set, or shift the individual bits that make up a value."
Booleans are represented by true and false in Java. Can we assume that that these values are represented by 1 and 0, respectively as in C++, etc.? Exactly how is Java representing these Boolean values in memory, and how many bits are in these representation? 1, 8, 16 bits?
Thanks
Online
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.932 :
In java, boolean is an independent type. It is not represented by 0 or 1. Its actual size is not specified in jls and is not important either.
Who is online
Users browsing this forum: Bing [Bot] and 7 guests