Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

instanceof operator on OCA  RSS feed

 
Ranch Hand
Posts: 94
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers!
I'm reading Scott and Jeanne book and re-reading some parts of Kathy and Bart one on OCAJP.
The former states that it instanceof operator is not in the exam, the latter dedicates same pages on it.
Is it in or out?
 
Marshal
Posts: 5801
401
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to check official resources at Oracle in Review Exam Topics section.

My personal opinion, it isn't on the exam, but I'm not certain.

On the other hand, I think it usually would take longer to find an answer if it is on exam or not than understand "instanceof" operator itself. Regardless, just read about it, learn - look at it wider. Purpose is to learn something, not just pass exam, so if the book gives such an ability of learning, just learn and don't bother whether it is on exam or not.

What that would change for you?
 
Daniele Barell
Ranch Hand
Posts: 94
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:Try to check official resources at Oracle in Review Exam Topics section.

My personal opinion, it isn't on the exam, but I'm not certain.

On the other hand, I think it usually would take longer to find an answer if it is on exam or not than understand "instanceof" operator itself. Regardless, just read about it, learn - look at it wider. Purpose is to learn something, not just pass exam, so if the book gives such an ability of learning, just learn and don't bother whether it is on exam or not.


Hi Liutauras !
As a general adress I completely agree with you...

Liutauras Vilda wrote:What that would change for you?


...But for the exam I think it changes a bit. It could tricks you for example in such a thing

The answer is false but it's a nuance as the a the type IS-A String

Or it could change from the operator precedence perspective...do you remember where instanceof is located in operator precedence?
Or it could tricks you a thing like this:

What would be the result?
 
Daniele Barell
Ranch Hand
Posts: 94
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Moving out of the results forum.


Oh! Sorry...
 
Liutauras Vilda
Marshal
Posts: 5801
401
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I see your concerns. These might be valid. But I'm still on the same, I'd say just go through this topic, finally it shouldn't extend your learning efforts significantly in the full context of preparation.

One of my professors in uni (it was Software and Programming III module) some time ago said: "You'll struggle in this module due to the material size it covers and courseworks it contains, most likely you'll curse me, some of you, actually most of you will hate me - and finally you'll thank me after some time.". I did my last part

Appreciate what you manage to learn and actually understand during the preparation, so go for it without a second thought.

Also, in case things happen, don't concentrate on side pieces as what material they give during exam, they give one pen or two, why they don't give three. Do they allow take notes out, why not. Can you do that or that, is mouse wireless or cordless or laser... - saying this because you'd be surprised how much energy people spend finding out those things.

Get knowledge, and other things will have less and less significance. Good luck on exam. Don't forget to come back so we could congratulate you To most of people I say, don't give pressure to yourself - be prepared to lose also, and in case that happens, remember - it isn't the end, once you put efforts, good day will come sooner or later. Don't put too much weight on the exam. Just go for fun and for a nice puzzle challenge day.

When you finish with book - I'd recommend to get some mock tests to get some actual sense of the exam flow, so that would be useful for sure.

 
Marshal
Posts: 59392
187
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniele Barell wrote:. . . The answer is false but it's a nuance as the a the type IS-A String . . .

That is the usual behaviour of instanceof which you can read about in the Java® Language Specification (=JLS). It also tells you what the result of adding apples and oranges in your example would be. You need to know about how instanceof behaves when presented with a null as its right operand in order to write a correct equals() method.
 
Daniele Barell
Ranch Hand
Posts: 94
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:Ok, I see your concerns. These might be valid. But I'm still on the same, I'd say just go through this topic, finally it shouldn't extend your learning efforts significantly in the full context of preparation.

One of my professors in uni (it was Software and Programming III module) some time ago said: "You'll struggle in this module due to the material size it covers and courseworks it contains, most likely you'll curse me, some of you, actually most of you will hate me - and finally you'll thank me after some time.". I did my last part

Appreciate what you manage to learn and actually understand during the preparation, so go for it without a second thought.

Also, in case things happen, don't concentrate on side pieces as what material they give during exam, they give one pen or two, why they don't give three. Do they allow take notes out, why not. Can you do that or that, is mouse wireless or cordless or laser... - saying this because you'd be surprised how much energy people spend finding out those things.


Liutauras I must thank you for the wise and kind words you spent on this post.
I've had no teachers to hate or thank in programming, I studied graphic and advertising and now I'm struggling to become...I dunno... a sort of self made programmer. Maybe I only liked the metaphor of travelling in a peculiar land of knowledge.
I was in doubt if posting this question this morning because I knew it was a relatively small subject. Yet I did it also because I know some intersting excursiveness can bear in these saloon!

Liutauras Vilda wrote:
Get knowledge, and other things will have less and less significance. Good luck on exam. Don't forget to come back so we could congratulate you To most of people I say, don't give pressure to yourself - be prepared to lose also, and in case that happens, remember - it isn't the end, once you put efforts, good day will come sooner or later. Don't put too much weight on the exam. Just go for fun and for a nice puzzle challenge day.


I feel I'm not prepared for the exam still. Most of the time I try a few questions from a mock exam I feel very uncomfortable, disorientated. It's not a mere knowledge problem.
Maybe I consider it too important.  

Liutauras Vilda wrote:
When you finish with book - I'd recommend to get some mock tests to get some actual sense of the exam flow, so that would be useful for sure.


OK!

 
Daniele Barell
Ranch Hand
Posts: 94
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Daniele Barell wrote:. . . The answer is false but it's a nuance as the a the type IS-A String . . .

That is the usual behaviour of instanceof which you can read about in the Java® Language Specification (=JLS). It also tells you what the result of adding apples and oranges in your example would be. You need to know about how instanceof behaves when presented with a null as its right operand in order to write a correct equals() method.



Hi Campbell!

I can see JLS is fundamental... but don't you feel  when you read it?
 
Campbell Ritchie
Marshal
Posts: 59392
187
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If at all possible, find somebody skilled to help you learn programming.
There are lots of skilled people here
 
Sheriff
Posts: 23585
48
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniele Barell wrote:I can see JLS is fundamental... but don't you feel  when you read it?



For me, the JLS is the absolutely last thing I look at when I'm trying to understand some feature of Java. It's only when all of the other training resources and on-line tutorials and so on have failed to answer my question when I look there.
 
Campbell Ritchie
Marshal
Posts: 59392
187
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, but I do realise that the JLS can be difficult to read. Since it is written in a technical style, you get sections where you have to follow links; in the part I linked to it says something like if a cast would fail to compile, then instanceof will fail to compile similarly, but you have to follow a link to find out about that.
 
author & internet detective
Marshal
Posts: 38366
645
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The OCA definitely doesn't try to trick you with instanceof. It likely won't appear on the exam at all. But if it does, you just need to know it returns a boolean.

For the OCP, you need to know a lot more - such as what happens with interfaces vs concrete classes
 
Daniele Barell
Ranch Hand
Posts: 94
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne.
For now OCP is in the outer space...
 
crispy bacon. crispy tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!