Win a copy of Rust Web Development this week in the Other Languages forum!

Henno Vermeulen

Ranch Hand
+ Follow
since May 06, 2015
Henno likes ...
Eclipse IDE Java
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Henno Vermeulen

Frits Walraven wrote:I made this list of all the documents that are involved in the WSD exam. The mentioned study notes and book cover some of the topics but there is definitely a gap. You can fill that gap of theoretical knowlegde by following that list.

Thank you for the clarification, I guess it doesn't hurt to read the same information from multiple sources.
Awesome score, congratulations!

Thank you for the tips. I have a question about the suggested preparation: the OCEJWSD-Links page suggests to read some of the official documents from the JCP and W3C. Did you also do this or do you think this is unnecessary?
OCP mock exam Objective 11 concurrency question 1. Class Account correctly uses a ReentrantLock to protect the value field, but method getValue() doesn't use the lock to read the value field.
Correct me if I'm wrong, but this can suffer from visibility issues due to a thread caching the value.
So I selected answer A which says this class is not thread safe.

The lock should als be used to read the value, or the value field should be volatile.
According to the answer to Question 56 of OCP exam 2, the following statement is false: "In an assert statement, the expression after the : (colon) can be any Java expression."
The explanation is that you cannot put a method invocation of a void method after the semicolon. This may be true, but is this really an expression?

I thought an expression returns a value by definition... Because you can put any value after the colon, the statement should be true. Indeed according to the official documentation on expressions "An expression is a construct made up of variables, operators, and method invocations, which are constructed according to the syntax of the language, that evaluates to a single value."

Perhaps technically a void method call is an expression just like other method calls? Still, not a well-posed question I suppose.
Thank you both for your answers!

Indeed I don't think the advantage of not typing "stream" outweighs the disadvantage of having to give each collection interface filter/map/etc... methods.
And indeed it's good to be explicit about exactly what type you are collecting from a stream. And yes, I will be using the static import to shorten that a bit.
6 years ago
AFAIK lambda's and streams were designed to help reduce boilerplate code and provide new possibilities such as parallel streams.
Still I feel it also adds boilerplate code in the common case when you are working with Lists/Collections:

  • At the beginning you have to explicitly call .stream() on a collection before using stream methods such as filter
  • You have to add code to explicitly convert a stream back to a List

  • E.g. to get a list of all even numbers in a list you would write something like:

    Why isn't it possible to do something like

    to do the same? Is there a shorter alternative to the first line of code?

    My guess is that this would require either a larger language change, or this would lead to combinatorial explosion of default methods in the collection interfaces. Am I right?
    6 years ago
    Thank you for your answers. I think we can summarize this discussion by saying that:

    encapsulation's main benefit is maintainability but generally does help for reusability.
    Yes exactly, if radius wasn't encapsulated, the client code is burdened with ensuring the invariants are not violated making the class harder to reuse. I am actually suggesting this may be the answer in my original post. Still I'm not sure if this is really the reason. A class could provide BOTH methods to enforce it's invariants AND provide direct access to it's fields.

    Henno Vermeulen wrote:
    It is true that a poorly encapsulated class can be harder to reuse when it has certain invariants between it's fields that need to hold. Exposing the fields directly enforces the client of the class - instead of the code of the class itself - to ensure that these invariants are not violated. This is an extra burden on the client of the class, so indeed it is harder to reuse!

    Would this be their reasoning or am I missing a simple point...?

    On page 504 they say about this:

    that it "tries to resolve a directory within the context of a file. Since that doesn't make any sense, Java just tries its best and gives you nonsense.".
    However as mentioned in the book itself, an instance of Path does not know whether a file or directory referenced by it actually exists. In fact it contains no information on whether it is a file or directory.
    AFAIK on Unix/Linux and Windows it is allowed to create a directory whose name contains a dot and a file that does not have an extension.

    So Java actually does not give nonsense but does the only right thing to do here. For all it knows the Path referred to by "Model.pdf" may be a directory and the Path referred to by "dir" may be a file!

    The diagram on page 494 claims that the (java.nio.file.)Files class uses the Paths class. This is not correct. It uses the Path interface!
    Thank you so much! I actually did have a few Belgian beers this Saturday . They are the best!
    6 years ago
    (Mostly in reply to the original question)

    I agree that the exam is MUCH more focused on recognizing correct and incorrect Java constructs/syntax than in learning how to properly implement business requirements in Java.
    Yet it does teach you the fundamental nuts and bolts of the language. You do have to think more like a compiler than someone implementing a piece of business logic. Still, having that knowledge doesn't hurt and you don't have to give up your higher-level knowledge to learn it... I have years of experience writing Java code and still the exam questions (and especially mock exam questions) were challenging because they also test you on things that the compiler normally catches so that you fix it without a blink of the eye, some things you may never use in practice and some things you can quickly look up. Still I found it a nice experience to learn some of these details. It improves how I can analyze a piece of code and know what is legal and what is not, and being able to explain why this is so without having to guess. So I do have the feeling it made me a better programmer, though it won't hugely affect my performance on the job.

    Others have made a valid point that passing the exam can also prove to others (including a possible employer) that you have a good grasp of the Java fundamentals, that you have a good attention to detail and can concentrate for a longer period of time.

    As to retraining the brain: I scored 98% on the OCA, more than I could ever hope for! So I guess I did manage to do this... What I did is first going back to the basics. Even though I knew how to use many of the topics in practice, I still carefully read a study guide (the K&B book), as well as the Java tutorials listed by Oracle for the OCA. This allowed me to pick up details I didn't know before. But more importantly: I made all of the practice questions and mock exam questions provided with the study guide, as well as bought and made the Enthuware mock exams. I focused on the mistakes I made and made notes on how to prevent these type of mistakes in the future. This is either memorizing a detailed piece of knowledge I had missed, or learning how to better tackle the exam questions, e.g. by checking for certain pitfalls. See also my tips on this post I made.

    Good luck with studying!
    Wow congratulations!

    I recently passed OCA 7 with 98% -- at age 35, not at 14 :-) -- and wrote how I studied achieve this score here.
    It basically boils down to careful studying and getting a lot of practice through creating small test programs and doing the Enthuware test exams and especially learning from what questions you answered wrong.
    6 years ago
    I forgot to mention some things I also did while studying:

  • I also read all of the Java tutorials from Oracle that are listed as the topics covered on the exam (once). They can be found here.
  • While studying I created many small test classes to get a feel for how it works, what compiles and what doesn't.
  • Take notes of the (type of) mistakes I made to prevent making them in the future.
  • 6 years ago
    Congratulations on a very good score!

    You're probably one of the first doing the new Java 8 exam right?
    When I started studying back in November of last year, this exam was still in beta and I like the K&B book which is still for Java 7, so I decided to go for the older Java 7 instead. This morning I passed the OCA (1Z0-803).
    6 years ago