About Question enthuware.ocpjp.v7.2.1235 :

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

Moderator: admin

Post Reply
muttley
Posts: 19
Joined: Thu Feb 28, 2013 9:47 am
Contact:

About Question enthuware.ocpjp.v7.2.1235 :

Post by muttley »

You want to execute a task that returns a result without blocking. Which of the following classes from java.util.concurrent package will be required to achieve this?
Callable, ExecutorService and Future are not classes.

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

Re: About Question enthuware.ocpjp.v7.2.1235 :

Post by admin »

While it is true that these are interfaces, it is common practice to call both (interface and class) as class when the difference is irrelevant or is not to be "revealed" for the point in discussion. After all, there is a "class" file with extension .class, not .interface :)


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

Alexey Berezkin
Posts: 20
Joined: Fri Jun 19, 2015 9:17 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1235 :

Post by Alexey Berezkin »

The common word correctly addressing both classes and interfaces is type. BTW, it may be also used for enums and primitive types, if you want to include them into a question :)

colmkav
Posts: 21
Joined: Thu Jul 16, 2015 4:22 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1235 :

Post by colmkav »

Alexey Berezkin wrote:The common word correctly addressing both classes and interfaces is type. BTW, it may be also used for enums and primitive types, if you want to include them into a question :)
That's ridiculous. Some questions you will get wrong if you use this interpretation that an interface is a class. Is the exam still giving such incorrect questions?

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

Re: About Question enthuware.ocpjp.v7.2.1235 :

Post by admin »

We have seen candidates getting questions that are somewhat vague or ambiguous. That is why we have included such questions. It is very easy for us to remove or alter such questions than to be at the receiving end of anger from our customers but then we will not be able to make the reader aware of such issues that they may face in the exam.

So our suggestion is to not read too much into the statement and rely on common sense.

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

toolforger
Posts: 38
Joined: Fri Nov 13, 2015 4:40 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1235 :

Post by toolforger »

Common sense won't help. Here "classes" is supposed to include interfaces, in other questions, it is supposed to exclude them.
I don't know whether that inconsistency is in the exam. Is there a possibility that people report inaccurate information from their exam experience?

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

Re: About Question enthuware.ocpjp.v7.2.1235 :

Post by admin »

It is possible that some information received from test takers is inaccurate. But at the same time, it is also true that there are such inaccuracies in the exam.

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

Nisim123
Posts: 42
Joined: Mon Jan 20, 2014 2:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1235 :

Post by Nisim123 »

Please excuse me for the this question that might sound trivial for some of you,
but the way the question is asked :
You want to execute a task that returns a result without blocking.........
So by saying without blocking what do they actually mean?
I suppose it does not mean simply waiting for a task to end until we start the second one...??? :?

toolforger
Posts: 38
Joined: Fri Nov 13, 2015 4:40 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1235 :

Post by toolforger »

"Blocking" means "stopping execution to wait for some other process to produce some kind of a result". Often I/O, in a multithreading context it would be waiting for another thread to e.g. terminate, or deliver some data.

Nisim123
Posts: 42
Joined: Mon Jan 20, 2014 2:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1235 :

Post by Nisim123 »

Thanks tooforger, so I realize that my assumption was not so far from truth,
BTW where did you get the definition of the term blocking ? since i went through the ks&&bb guide
chapter on concurrency and didn't find it there.... :shock:

toolforger
Posts: 38
Joined: Fri Nov 13, 2015 4:40 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1235 :

Post by toolforger »

It's a general IT term. I first read it in descriptons of Unix system calls.

doziransky
Posts: 8
Joined: Wed Mar 16, 2016 10:57 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1235 :

Post by doziransky »

Hi,

So I'm a bit confused about something.

I have always understood that runnables don't return anything while callables do but then I went into the API documentation for ExecutorService today and saw this:

<T> Future<T> submit(Runnable task,
T result)
Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return the given result upon successful completion.
Parameters:
task - the task to submit
result - the result to return
Returns:
a Future representing pending completion of the task
Throws:
RejectedExecutionException - if the task cannot be scheduled for execution
NullPointerException - if the task is null

If runnables never return anything then why is this method in the API?

Thanks

toolforger
Posts: 38
Joined: Fri Nov 13, 2015 4:40 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1235 :

Post by toolforger »

result is passed in to submit() and returned in the Future when the Runnable is finished.
That's useful if the Runnable modifies result.
It is also useful if you need to pass a Future into some API, already have the result ready but don't want to have it processed before the Runnable is finished.

Sai Divya sree
Posts: 14
Joined: Mon Jun 20, 2016 11:16 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1235 :

Post by Sai Divya sree »

I read in K&B book,
Callable<Integer> c= new Callable();
Future<Integer> f= ex.submit(c);
try{
Integer v=f.get(); //blocks until done
System.out.println(..);
}
catch(InterruptedException| ExecutionException ex){
System.out.println(..)
}
It says:
Interrupted Exception:Raised when the thread calling the Future's get() method is interrupted before the result can be returned.
Now my question is should the get() method always placed inside the try/catch or throws exception mentioned.Am I correct?

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

Re: About Question enthuware.ocpjp.v7.2.1235 :

Post by admin »

Well, InterruptedException is a checked exception so you have to either put the call to get in a try catch or declare the exception in throws clause the method. This is same as for any other checked exception.
-Paul.
If you like our products and services, please help us by posting your review here.

jagoneye
Posts: 97
Joined: Wed Dec 28, 2016 9:00 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1235 :

Post by jagoneye »

admin wrote:We have seen candidates getting questions that are somewhat vague or ambiguous. That is why we have included such questions. It is very easy for us to remove or alter such questions than to be at the receiving end of anger from our customers but then we will not be able to make the reader aware of such issues that they may face in the exam.

So our suggestion is to not read too much into the statement and rely on common sense.

HTH,
Paul.
I have huge respect for this! I hope all the hard work of you guys as well as me preparing for this monster test pays off! :D

Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests