monikma / monikma.github.io

Mona's learning blog
Apache License 2.0
6 stars 6 forks source link

Preparation for Java 8 OCA 1Z0 808 exam #30

Open monikma opened 8 years ago

VillieldrVuur commented 7 years ago

Hi,

Thanks for the awesome rundown of surprises. I'm sure this is going to help a lot of people out.

Could you please clarify the content about list.toArray(); ?

I created a test application that changes the array and the List, but I don't see any changes in the contents of the related data structure.

Also, I don't get an exception when I change the sizes of the array or List.

monikma commented 7 years ago

Hello VillieldrVuur,

Indeed, you spotted a mistake :) What I had in mind while writing it, was Arrays.asList(), not list.toArray(). And I just checked that you cannot pass the array to Arrays.asList(), and the toArray() method indeed creates a new array - therefore the comment about changes in one reflected in another one does not make sense, as anyway it seems that there is no access to the underlying array. The exception comment is still valid though - you can get it by calling list.remove(0), after the list has been created by Arrays.asList().

Thanks for spotting that, I have corrected the text :)

Monika

VillieldrVuur commented 7 years ago

Another point:

Under the section "On the self assesment test (40% correct)", you say "printing list without .toString() prints only the object ref of course"

Are you sure of this? I wrote a small app with the code: List stringList = Arrays.asList("1", "2", "3", "4"); System.out.println(stringList); System.out.println(stringList.toString());

And, the output is: [1, 2, 3, 4] [1, 2, 3, 4]

Sorry for the constant comments. I'm going through this as I study for the exam :)

monikma commented 7 years ago

Hello, no problem, I'm glad someone makes use of it :)

If you look inside implementation of System.out.println() you will see:

public void println(Object x) { String s = String.valueOf(x);

which calls toString(), so in the end those two lines do exactly the same.. I guess I meant something else than System.out.println(), though now spent some time trying to figure it out and I cannot think of any way of printing something without having it converted to String. I guess I will just remove that line, please disregard it :) Ah, and remember not to mix up printing an array with printing a list :P

VillieldrVuur commented 7 years ago

Ja, I think you meant printing an Array, although it will print the object reference regardless. Btw, would you mind if, when I pass the exam, I link this page for other people? It's proving to be extremely helpful with regards to preparing for the exam. It's weird how I had to search for a while to find any site that could provide anyone's experiences with the exam :(

monikma commented 7 years ago

Yes sure I don't mind, the site is public :) Sharing it is even recommended ;)

VillieldrVuur commented 7 years ago

Awesome, I will do so. Although, I will definitely be adding as much as I can as I go along ;)

VillieldrVuur commented 7 years ago

Hey, it's me again! I've just summarised the contents of the book. Would it be possible for you to provide detail as to how you studied for the exam?

As a Java developer, I feel confident about this exam, but I KNOW there will be tricks that will appear. What did you do to make sure that you are prepared for the exam apart from reading the materials?

monikma commented 7 years ago

Hi!

I guess that by now it's a bit late to answer, hehe ;) How did it go?

Basically I read the book, did the tests from the book (in real IDE) and wrote this blog post.. to be honest I was just so tired with studying that I thought "ok if this is not enough to pass then I don't want it, as it's not worth any more of my time", I think this is a good indicator that one is ready (to pass or to fail) :P

saketb01 commented 7 years ago

Hi monami555,

Great stuff! Very thoughtful of you to put this up for those following your footsteps :)

Comparing your OCA chapter scores with what you scored in the actual exam, how would you rate the difficulty level of the real test?

monikma commented 7 years ago

Hi thanks :) I do not remember it that well anymore but I think that the book was quite realistically reflecting the difficulty of the exam. For sure the parts where I scored less with the book I have repeated again (40% with the book is for sure not enough) and tried to memorise the weak points, as well as learn what to pay attention to in how the questions are formulated (bastards!). I would say that the book was for sure enough.

Previously I did 2 Spring exams and for them I felt I needed to know 100% to fit in the error margin due to some questions being not precise enough. I remember with Java it was not that tough, but still I had the habit of aiming at 100%, and with that I do not remember any impression that it was hard.

ldejonghe commented 7 years ago

Nice summary, well done. However, beware of your statement :

it is possible to override a protected method with a public; if the method is not protected but private, there is no compiler error, and the two are completely separate;

Note that if you code correctly, when overriding a method, you should use the annotation Override. It has been made especially for the purpose detecting anomalies, cfr. misspelling the function in extending class. (or a function being private in the parent class)
@Override

A result, you will get an error in case you override a method which has been declared private in the parent , since a private function in a parent class is not seen by the extended class(only that specific class can use it) . So, it is perfectly normal you then have 2 separate functions. But you will have compiler errors if you use the Override annotation (and you should always use it when you have the intention to override, to have a check on the function finding a match in the parent)

naikel commented 6 years ago

@ldejonghe even though you're right, this is an article for preparation to the OCA Java 8 exam, and all annotations are way out of scope for this certification. Annotations are covered in the OCP exam. So basically in this exam, they test you so you can identify the inheritance problems, not your compiler.

cyberglad commented 6 years ago

Exam is full of errors, from 70 question I counted about 6 or 7 errors. Wrong results, blocks that actually compile (when it says it wouldn't), unreachable code, let alone syntax erros. When I did the one in 2003 (I think it was Java 1.4), it was not that bad. The new one is terrible. They need to revise it.