James Pittendreigh

Ranch Hand
+ Follow
since Oct 14, 2013
James likes ...
Spring Java Linux
Cows and Likes
Cows
Total received
5
In last 30 days
0
Total given
0
Likes
Total received
23
Received in last 30 days
0
Total given
4
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by James Pittendreigh

Nishra Nasar wrote:I would like to know whether i can eligible for OCPJP(Java SE 8 II) without OCAJP (Java SE 8 I) as most of of basic java theories are covered within my HND.



A little off-topic, but the entry requirements for the Programmer exam is "Oracle Certified Associate, Java SE 8 Programmer", as stated on the Oracle website. You could try asking them nicely but I almost guarantee the answer will be no.
Thanks for all the replies - this helps a lot.

I tweeted the question to OracleCertification, which resulted in radio silence. You guys are much better. Thanks again.

The next thing I need to remember is that there's no overloaded version that takes a predicate.
Hi all,

I have noticed an inconsistency, or difference of opinion regarding findAny() from the Enthuware exams and The Boyarsky/Selikoff OCP 8 book.

So in the book, Chap 7, p372

Since order is not guaranteed with parallel streams, methods such as findAny() on parallel streams may result in unexpected behavior. Let’s take a look at the results of findAny() applied to a serial stream:

System.out.print(Arrays.asList(1,2,3,4,5,6).stream().findAny().get());

This code consistently outputs the first value in the serial stream, 1.

With a parallel stream, the JVM can create any number of threads to process the stream. When you call findAny() on a parallel stream, the JVM selects the first thread to finish the task and retrieves its data:

System.out.print(Arrays.asList(1,2,3,4,5,6).parallelStream().findAny().get());

The result is that the output could be 4, 1, or really any value in the stream. You can see that with parallel streams, the results of findAny() are no longer predictable.



So in the book, it details, or rather implies, that the output of findAny(), when used in a sequential/in series stream, is deterministic.

However, Whilst doing an Enthuware practice test, I came across the following question (Q30 - OCP upgrade 7 to 8 test 1):


What will the following code print?

Object v1 = IntStream.rangeClosed(10, 15)
       .boxed()
       .filter(x->x>12)
       .parallel()
       .findAny();

Object v2 = IntStream.rangeClosed(10, 15)
       .boxed()
       .filter(x->x>12)
       .sequential()
       .findAny();

System.out.println(v1+":"+v2);

(Note: < and > in the options below denote the possible output and not the sign themselves.)



With the Answer being:

<An Optional containing 13, 14, or 15>:<An Optional containing 13, 14, or 15>



With the explaination:

The second stream is sequential and therefore, ideally, findAny should return the first element. However, findAny is deliberately designed to be non-deterministic. Its API specifically says that it may return any element from the stream. If you want to select the first element, you should use findFirst.



Which is entirely true. In the API it states:

"The behavior of this operation is explicitly nondeterministic; it is free to select any element in the stream. This is to allow for maximal performance in parallel operations; the cost is that multiple invocations on the same source may not return the same result. (If a stable result is desired, use findFirst() instead.)



This has also been discussed on the Enthuware forum, here: http://enthuware.com/forum/viewtopic.php?f=2&t=4148

So we clearly have a difference of opinion. I've ran this on my machine and I always get the first element. But the API clearly states that I should not rely on that, and it does not explicitly state that it is nondeterministic for parallel streams exlusively.

Great, and in practice, I would use findFirst() if I wanted the first element regardless of stream. Problem solved... (unless you want to pass the exam)....

So, in an exam, if I were to get a similar question relating to findAny() on a sequential stream, do I:
  • Select the first element in the stream, as per the book and as per the current implementation of the JDK I am running.
  • Select the option that could indicate that it could select any element of the stream, because the API says it is non-deterministic.


  • Really, I understand both sides. I just want to be able to select the option that will give me the mark.
    Hi all,

    A while back I made a concurrent collections diagram whilst studying for my OCJP, but find I'm using useful at work as well. Anyway thought I'd share it for those studying the OCJP.

    Any suggestions/corrections/etc, please reply here or create an issue on github.

    There's a SVG version with working links to the javadoc for the interfaces and classes over on the github https://github.com/jaymoid/JavaConcurrentCollectionsDiagram

    Cheers ~ James

    (right click -> "view image" to embiggen)


    Hi Jeanne, aaah I see what you mean, the other examples in the table print using foreach, or collect via a collector, which are all terminal operations, but the peek intermediate operation that does the printing is not destructive (but does need a terminal operation in order to run).

    Thanks for the info, and for the link to the errata.

    Hi Jeanne/Scott,

    Think I may have spotted one. P204. Table 4.5, which details how to print a stream, it has several options, and states:



    Would not be destrictive to the stream. But as count() is a terminal operator, the stream is no longer usable after it is invoked.


    Yields:

    1
    2
    3
    Exception in thread "main" java.lang.IllegalStateException: stream has already been operated upon or closed



    Apologies if incorrect.

    Also I was wondering if there is an errata in one place like the one that Roel kindly administrated for the SE 7 study guide?  I did have a look around before posting this one, but it really would be handy to have a definitive errata in one place.

    many thanks, James
    Any reason why the answers to the exercises aren't in the book? Some aren't code based and would be good to see what Cay's answers were.
    4 years ago
    I think that the path to OCP 8 is easier for SCJP/OCP 6 (and earlier upgrades) than it is for OCP 7 holders, hear me out....

    If you have OCP 6 or lower... to obtain OCP 8, you have a £155 exam, with 60 questions, and a pass rate of 63%. It is 130 minutes in duration.

    That's 60 questions with which to cover 8 big topics (7.5 questions on each topic by way of average)

    If you have Java 7 and wish to upgrade... you have a £155 exam, with 81 questions, and pass rate of 65%. It is 150 minutes in duration.

    That's 81 questions, 21 more than the 6 or lower upgrade.... to cover ALL the new features in from 7 to 8 to a very in depth level, and you need a higher pass rate of 65%! There seems to be four main topics: Lambdas, Streaming API, Method References, and the Date Time mods. That's 20 questions per section, really a lot of that is going to be lambdas, streaming, and everything functional programming. i.e. the really tricky new stuff.

    How can Oracle justify this?

    More elements were added to Java from 6 to 8, so by normal logic you'd think there would be more questions to ensure that topic should be tested equally... But no, 6 has less questions, and a lower pass rate, and a shorter exam, for the same price.

    The changes to Java 8 are substantial and by no means trivial. As a OCP 6 and OCP 7 holder, surely I'd be mad to put myself through the 7 upgrade path, when 6 -> 8 seems so much easier! Especially as all the OCJP 7 stuff is fresh in my mind. Part of me thinks that I could pass 6 to 8 upgrade now as long as I only get the Java 8 questions wrong as you only need 63% (and I could get the earlier train home!)

    Can't help but think that the 6 to 8 upgrade exam cheapens the worth of the OCP 8 certificate.

    Surely I can't be the only one.

    p.s. Just received my Boyarsky/Selikoff OCP 8 Study guide in the post today, nice work guys, congrats on the new book!

    p.p.s. Seems Jeanne Boyarsky has already reported similar puzzlement regarding the inclusion/exclusion of certain topics on her blog: http://www.selikoff.net/2015/08/23/what-does-it-mean-to-be-ocp-java-programmer-ii-certified/
    I would study everything evenly/equally first, but revisiting any subjects you have trouble with. When you feel comfortable with all the topics, you should start doing some practice exams. When you see the results of the practice exams it will soon become apparent which topics require more study + coding. Some software based practice exams (like Enthuware) will split up the topics into sections and tell you where you are weakest.

    Also... a tip when you are doing practice exams and you get stumped on a question: write down the particular element that is troubling you (on a separate piece of paper to your notes), write down what particular bit of knowledge you may be missing, and any assumptions you are making in the exam. E.g. "Are ResultSet cursors 0-based or 1-based? Assumption: they are 1-based." ... If you had made that assumption in the practice exam and it lead to a correct answer - then there's a good chance you might not follow it up and cement the knowledge afterwards.... So after the practice exam, get your results, review what you got wrong and why, and then also review your notes on what you need to do some additional study, and see if your assumptions were correct, if not, why.
    Anyone know how long it takes for Oracle to send out the badges please? I've got my OCJP 6 one recently, but I just took my OCJP 7 and am waiting for the YourAcclaim badge/email. Can't find any info as to how long it'll take on the oracle site.

    thanks
    Thanks Paul....

    I don't think I did no, Predicate and Filtered rowsets were definitely in though, but the exam topics are so high level, like: "Construct and use RowSet objects using the RowSetProvider class and the RowSetFactory interface" but how much detail do you need to know about each individual rowset and what you are likely to be tested on is a bit of a mystery. But I'm definitely glad I looked a bit deeper into the predicate interface and the Standard Open options (good to know anyway!).

    Cheers
    James
    Cheers for the reply Paul.

    Passed with 95%, and did all three enthuware exams as practice. Really good value for money and neat software too, will definitely use again for the next exam I do. The forums were a good way to report the odd anamoly.

    I also got the Kaplan "official" test which had a question that had incorrect answer, and no forum (but a feedback email feature), and was about three times the price, and only available via the web.

    Cheers
    James
    Thanks for your reply Roel, you are completely right here. I have done some additional reading on the subject and understand the reason why volatile is not needed when you synchronize access to the instance via getInstance.

    I think I was under the illusion that if you didn't use volatile that other threads may see a "half-initialized" version of the instance, but seeing as the instantiation is done in the synchronized method (if you synchronize the getInstance() method), other threads would only get access to it after it has been fully initialized anyway.

    Definitely not one for the errata. Thanks again for the detailed reply.
    Does anyone know if:
    * OpenOption and the StandardOpenOption implementation
    * Predicate
    ... are on the Java 7 upgrade exam?

    The enthuware guys have included the questions in the practice exam but I am unable to see any details about either in the exam topics, or the Kathy Sierra / Bert Bates book, or the Ganesh / Tushar Sharmer book.

    Over on the enthuware forums, they maintain they have seen questions on the above [here and here], but the cynic inside me thinks they are just saying that so they don't have to change their tests.

    Either two books are missing vital information, or the Enthuware chaps have redundant info in their exam.

    any ideas?

    Cheers
    James

    p.s. The Enthuware exams are good, apart from causing the above ambiguity.

    Bindurekha Ragu wrote:Thank Paul for your brief post about enthuware.



    I thought Paul was quite thorough personally.