About Question com.enthuware.ets.scjp.v6.2.705 :

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

Moderator: admin

Post Reply
ETS User

About Question com.enthuware.ets.scjp.v6.2.705 :

Post by ETS User »

This assertion in explanation is not correct.

"So, wait()/notiy()/notifyAll() can only be called from synchronized methods because then it will be sure that the thread really has the lock for the object (resource)"

"Can only be called" is not true. This is incorrect. Of course they can be called!

The explanations about where the methods "wait", "notify" and "notifyAll" can be called, are confusing in some books (like Katty Sierra and Bates) and in some questions in this program.

When someone types "can only" or "must" speak in terms of obligation. The correct term is "should" because it speaks in terms of recommendation, there is no such thing as an "obligation" to indicate where these methods should be called like a compulsory.

In the book of Sierra and Bates usually use the verb "must" instead of should. You're always free to call this methods in a place of code out of a "synchronized block". Of course.

Is not necessary and is not an obligation to call this methods inside a synchronized context. The resultant IllegalMonitorStateException is other thing. It's is secondary, ¿the code compile? Yes, then call this methods out of synchronized blocks is possible, and correct for compile purposes.

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

Re: About Question com.enthuware.ets.scjp.v6.2.705 :

Post by admin »

I agree with the general point that you have explained. However, I also think that can and should really depend on the context. If the context focuses on mere compilation, then yes, you can call these methods without synchronization. But if the context focuses on successful execution, then you cannot.

It is like saying, can I jump from a 10 story building? Of course, I can. That I will die is another thing. If dieing is indeed a secondary thing then can is valid otherwise it is not.

Based on the context, some things can be implicitly assumed. They fall under reasonable expectation. No one writes a program merely to make it compile. They write it to make it work. In that sense, I think the statement is correct.

On the other hand, some questions explicitly ask whether a given code will compile or not. In such cases, the focus is merely on compilation and in such cases, the statement is wrong.

Hope it make sense.

thank you!
Paul.
If you like our products and services, please help us by posting your review here.

Guest

Re: About Question com.enthuware.ets.scjp.v6.2.705 :

Post by Guest »

Thanks for fast reply.

Perhaps the problem is the way of think acquired for someone that is preparing for this exam.

Knowing what is allowed to do (in the strict sense of the word), where and how is a necessity (perhaps an obsession) for the student of OCJP!

The student of this certification converts itself in a compiler of JAVA code. This work is insane for the brain :D

Kinds regards from Spain!

Post Reply

Who is online

Users browsing this forum: No registered users and 229 guests