Zanna Bianca

Greenhorn
+ Follow
since Oct 19, 2015
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
7
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Zanna Bianca

Hi again,
I tried the same code with a big array (lenght=1000) and the result was that it is needed an Atomic variable, otherwise you can have not the right sum
Hi there,

First of all I would like to thank you for the great job with OCA/OCP Java SE8 Programmer Practive Tests Book!

I tried the code in Sybex OCA OCP Practice Test online Chapter 19 Q.23 with: "static int count=0;".



And as explained in the answer : If count was marked static, then the application would sum the elements correctly, printing 10. Indeed, it prints 10 correctly.
My question is: Why is it not needed to declare count as Atomic variable?
As more threads are working with count concurrently, I thought it would be necessary in order to keep consistency.

Please help me to understand!

Thanks

oh..in book is chap 20...sorry, my mistake..
I doubled checked this question can be found in Sybex OCA OCP Practice Test Chapter 19, not Chap 20, Q14.
Hi
I'm also confused here
My explanation could be that in this case the combiner cannot be considered a function of two variables f(u, a(i,t)) because a(i,t) returns always a constant. Therefore we have more something like: f(x) = x+c, whereas c is a constant. And the compatibility requirement between function combiner and function accumulator is not more relevant because the second one is a constant.
Though, a little help in order to understand better the explanation would be appreciated.
Thanks
thank you all very much! I think that is the best forum ever;)
8 years ago
Thank you for having me!:-)

Does it mean that i = i++ is never really useful?
8 years ago
oh you're right, it is indeed i = i++;
and in this way I got an infinite loop...now I'm more confused, why with only i++; I got a terminated loop? what is the difference?
8 years ago
The answer of one question in chapter 2 of "Oracle Certified Associate Java SE 8 Programmer I Study Guide - Jenny Boyarsky and Scott Selikoff" is 'The code contains an infinite loop and does not terminate.', but I tried it in Eclipse and it terminated after 11 times printed "Hello World":/

Here the question:

9. How many times will the following code print "Hello World"?

3: for(int i = 0; i<=10;){
4: i++;
5: System.out.println("Hello World");
6: }

A. 9

B.10

C.11

D. The code will not compile because of line 3.

E. The code will not compile because of line 5.

F. The code contains an infinite loop and does not terminate.

According to the book the answer is F:

"F. In this example, the update statement of the for loop is missing, which is fine as the
statement is optional, so option D is incorrect. The expression inside the loop increments
i but then assigns i the old value. Therefore, i ends the loop with the same value"

I don't see any explanation why it should assign i the old value? Could you please help me to understand?

Thanks
8 years ago