[HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Arold Aroldson
Posts: 21
Joined: Mon Nov 20, 2017 8:00 am
Contact:

[HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Post by Arold Aroldson »

In table in page 113. Boolean flag=false; sout(false != flag); prints false. You have a mistake in book.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Post by admin »

Yes, it has been fixed in update 6 released on Oct 7th 2018.
If you like our products and services, please help us by posting your review here.

Username987654
Posts: 95
Joined: Sat Dec 26, 2015 6:37 pm
Contact:

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Post by Username987654 »

instanceof discussion:
It returns true if the object pointed to by the reference
variable on the left is of the type (or a subtype) of the type given on
the left and false otherwise.
should be
It returns true if the object pointed to by the reference
variable on the left is of the type (or a subtype) of the type given on
the right and false otherwise.
?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Post by admin »

Correct. Will add to errata asap.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Username987654
Posts: 95
Joined: Sat Dec 26, 2015 6:37 pm
Contact:

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Post by Username987654 »

ok. Thank you for another excellent Enthuware product and excellent customer service.

Username987654
Posts: 95
Joined: Sat Dec 26, 2015 6:37 pm
Contact:

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Post by Username987654 »

Code: Select all

Object obj = new Double(10);//
System.out.println(obj != 10); //1  can’t compare a reference with a number
int a = 10; Double d = 10.0;
System.out.println(a != d);//2  prints false (book example)
I don't feel as if I have burned 1) into my mind completely. Why doesn't the compiler at 1) not have to allow for the possibility of a situation like 2) ?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Post by admin »

How can a reference be same as a primitive? obj is a reference. It can never be same a integer 10. Same with a and d. a is an primitive variable and d is a reference variable. Both are inherently different things and can never point to the same object (which is what == checks). The compiler knows that this comparison is nonsensical and most probably a programming mistake.
If you like our products and services, please help us by posting your review here.

Username987654
Posts: 95
Joined: Sat Dec 26, 2015 6:37 pm
Contact:

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Post by Username987654 »

admin wrote:
Sun Jul 07, 2019 8:56 pm
How can a reference be same as a primitive? obj is a reference. It can never be same a integer 10. Same with a and d. a is an primitive variable and d is a reference variable. Both are inherently different things and can never point to the same object (which is what == checks).
My blind spot is trying to understand why the compiler does not treat these the same.
admin wrote:
Sun Jul 07, 2019 8:56 pm
The compiler knows that this comparison is nonsensical and most probably a programming mistake.
I think the compiler does not treat these the same because of a very important piece of information that apparently I overlooked:
When used on two primitive values or a primitive value and a primitive wrapper, they check whether the two values are same or not.
The one that compiled (a != d) adhered to this rule, as does the first example box mentioned for ==, != (Binary) in the book? Whereas the other (obj != 10) did not adhere to this rule, as does the second example box mentioned for ==, != (Binary) in the book?. Thus, the compiler complained. Correct?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Post by admin »

Yes, sounds logical.
If you like our products and services, please help us by posting your review here.


DazedTurtle
Posts: 26
Joined: Wed Oct 02, 2019 1:42 pm
Contact:

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Post by DazedTurtle »

In the bit about the = operator:
It simply copies the value on the left to the variable on the right.
Pretty sure you switched left and right there.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 110, Sec. 5.1.1 - overview-of-operators-available-in-java]

Post by admin »

DazedTurtle wrote:
Mon Oct 07, 2019 1:11 pm
In the bit about the = operator:
It simply copies the value on the left to the variable on the right.
Pretty sure you switched left and right there.
Yes, added to the errata only a couple of days ago.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 27 guests