About Question com.enthuware.ocpjp.v7.2 _. _1083

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

Moderator: admin

Post Reply
sasha32003
Posts: 12
Joined: Tue Aug 05, 2014 2:47 am
Contact:

About Question com.enthuware.ocpjp.v7.2 _. _1083

Post by sasha32003 »

Given:

Code: Select all

public class Counter{
     static AtomicInteger ai = new AtomicInteger(0);
     public static void increment(){
        //1
     }
     //other valid code }
This class is supposed to keep an accurate count for the number of times the increment method is called. Several classes share this class and call its increment method. What should be inserted at //1 ?

I think there could be 3 valid answers:
1. ai.incrementAndGet();
2. ai.addAndGet(1);
3. ai.set(ai.get()+1); - What is wrong with this option?
Last edited by admin on Tue Oct 07, 2014 7:36 am, edited 1 time in total.
Reason: Scrambled qid

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

Re: About Question com.enthuware.ocpjp.v7.2.1083

Post by admin »

Did you read the explanation provided with the option?
ai.set(ai.get()+1); is not atomic. It is composed of two independent method calls. It is possible for another thread to change the count in between those two calls. That is why it is not valid.
If you like our products and services, please help us by posting your review here.

sasha32003
Posts: 12
Joined: Tue Aug 05, 2014 2:47 am
Contact:

Re: About Question com.enthuware.ocpjp.v7.2.1083

Post by sasha32003 »

admin wrote:Did you read the explanation provided with the option?
ai.set(ai.get()+1); is not atomic. It is composed of two independent method calls. It is possible for another thread to change the count in between those two calls. That is why it is not valid.

Hi. That is why I asked here. There was no such explanation.

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

Re: About Question com.enthuware.ocpjp.v7.2.1083

Post by admin »

That's weird. I do see an explanation with this option.
2.1083.png
2.1083.png (27.41 KiB) Viewed 5435 times
If you like our products and services, please help us by posting your review here.

sasha32003
Posts: 12
Joined: Tue Aug 05, 2014 2:47 am
Contact:

Re: About Question com.enthuware.ocpjp.v7.2.1083

Post by sasha32003 »

admin wrote:That's weird. I do see an explanation with this option.
The attachment 2.1083.png is no longer available
It is:
Attachments
Atomic.png
Atomic.png (235.99 KiB) Viewed 5433 times

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

Re: About Question com.enthuware.ocpjp.v7.2.1083

Post by admin »

What version of the question bank are you using?
If you like our products and services, please help us by posting your review here.

sasha32003
Posts: 12
Joined: Tue Aug 05, 2014 2:47 am
Contact:

Re: About Question com.enthuware.ocpjp.v7.2.1083

Post by sasha32003 »

admin wrote:What version of the question bank are you using?
Where do I look for version?
This is the .ets file that I am using: jqplusv7.ets

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

Re: About Question com.enthuware.ocpjp.v7.2.1083

Post by admin »

Just download the ets file from our website again. You can see the version using Tools/Check for Question Bank Update.
If you like our products and services, please help us by posting your review here.

sasha32003
Posts: 12
Joined: Tue Aug 05, 2014 2:47 am
Contact:

Re: About Question com.enthuware.ocpjp.v7.2.1083

Post by sasha32003 »

admin wrote:Just download the ets file from our website again. You can see the version using Tools/Check for Question Bank Update.
Thank you.

Post Reply

Who is online

Users browsing this forum: No registered users and 235 guests