Win a copy of Terraform in Action this week in the Cloud forum!

John Simon

Greenhorn
+ Follow
since Feb 01, 2017
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
3
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by John Simon

Well, IMHO, just because you don't foresee a potential need to add new animals at the time you originally write the code doesn't meant that you should go with a less than ideal design.  If you have an inkling that something is not quite right about what you're doing then you should refactor rather than leaving it for someone else to deal with in the future

Regards,

John

Viktor Logwin wrote:I have to say, the third chapter of the book was like hell for me. I was staring at this method references and didn't knew, what to do with it.
But in this chapter you only need to memorize, that there are alternatives to the lambda expressions. So you can write a lambda expression instead of a method reference. But the other way not always work. In the chapter 4 you will learn more built-in functional interfaces.

In my opinion, the method references sub-chapter shouldn't be there in the third chapter. It belongs to chapter 4. It makes much confusion.



"...like hell", "..much confusion" - , yes method references are the same for me.  I'm hoping that at some point the Java language dev team have the sense to know when to stop always trying to infer from context and seeking to reduce the amount of code that has to be typed to near zero...

Viktor Logwin wrote:Sorry, the second idea is what you need.


Yes, I wasn't aware of BiPredicate - but am now thanks to you.  I know my test class didn't do the same as the book example but it was the fact that the book said "This would be a nice way of filtering the data in a list." that got me thinking about it in the first place. I understand all of your answers but I'm still unsure as to what exactly the authors were getting at when they wrote the above - unless it was along the lines of your answers.
Hi Viktor

thanks for your reply.   Your suggestion of a separate method that defines the predicate in-line using the loop variable is a solution that I'd already come up with - I just wanted to be sure that there wasn't a way of doing it without having a separate method.

Regards,

John
Hi,

I'm stumped by something concerning Method References that starts at the bottom of p153 of Boyarsky, Selikoff OCP Java SE 8 Programmer II Study Guide 2016 edition. It states:


..Let's look at some examples from the Java API.  In each set, we show the lambda equivalent.
..
..
Next up is calling an instance method on a specific instance:
Line 17 shows that we want to call string.startsWith() and pass a single parameter to be supplied at runtime. This would be a nice way of filtering the data in a list.


I do not understand how line 17 would do anything - how can it be the equivalent of the lambda version on line 18? Where is the equivalent of the lambda version's "s" argument?

My test class (below) shows how a Predicate that uses a lambda can be used to filter a list but I cannot work out how to achieve the same thing with a Method Reference.  So, if someone could explain/demonstrate what to insert in the commented section of the code it would be much appreciated.


Thanks,

John

Liutauras Vilda wrote:John, just to re-iterate, what code formatting style you see on EnthuWare mock questions, this is what you should expect on actual exam basically. So I think you just need to get used to it. Give yourself some time.


Ok, thank you.  

Paul Anilprem wrote:
Can you please mention the question id of such a question (any one is fine) so that I can check it out? Because unless the point of the question is to test you on the format, the code should be decently (if not perfectly) formatted. Not to say that all the code in the exam is decently formatted, but we haven't seen anyone getting code that is all on one line or such. Our question bank doesn't have such questions either. If you saw something like that then there could be some other issue.



Sorry Paul, I didn't mean that all of the code was on one line - the formatting was fine.  And, to be absolutely clear, I'm not dissing EnthuWare at all. I meant that personally I generally find it hard to read statements that do not have spacing between the variables (e.g. the second last line in Q12 in the EnthuWare trial) and they take me an overly long time to decipher.  With regards to that Q12 (which I did actually get correct), it wasn't until just now that I read the explanation for it and saw "This is a simple but frustratingly time consuming question. Expect such questions in the exam.". Doh!

Thanks

John
Thanks Viktor, Paul.

The lack of line numbers doesn't bother me - the method of tagging a line with a // comment was clear enough.  I had more issue with, for instance, the lack of spacing especially given the amount of single character variable names and operators that were being crammed into a single statement where operator precedence comes into play.  The type of question that I currently spend/lose the most time on are those that involve nested loops where you need to keep track of variable and loop counters.  Whenever I see a question with a nested loops AND crammed statements my heart sinks as I've not yet come up with a quick surefire method of jotting down the values quickly in such a way that I can keep track of them.  

It all comes down to practice I guess but I'd really like to know whether I should expend more effort on being able to read scrappy, deliberately obfuscated code or whether my time is better spent understanding the subject that is the Java language.  If all of the code in the real exam is similarly deliberately obfuscated then I guess I'm in for a hard time.

John
Hi,

I've been working professionally as a Java Developer for a couple of years (I've been in IT since the mid-80's) but I'm new to the JavaRanch.  I've joined because I'm currently studying for the OCA exam and it has to be said that I have not found studying for it at all easy - the types of issues, code examples and programming style are so different to what I've worked with in real life.

I've studiously worked through the OCA Study Guide (by Jeanne Boyarsky and Scott Selikoff) and have done all of the chapter reviews, flash cards and the 3 online exams; I failed the first sample exam and passed the last two.  I'm now about to start doing the chapter reviews again and then will retake the sample exams.

After the 3 sample exams above I also did the EnthuWare trial questions and failed miserably by running out of time - I only managed to answer 17 of the 27 questions in 48 minutes and only just scrapped in with a 70% pass on those I did manage to answer.  I found the coding style of EnthuWare questions to be quite different to those in Jeanne and Scott's book and I was somewhat thrown by this.  I found the code really difficult to read and hence it took me longer to decipher.

This failure on my part with the EnthuWare trial questions (I have now bought the full suite) brings me to my question:  Is the coding style of questions of the real exam closer to EnthuWare's examples or those in Jeanne and Scott's book?  I'd just like to know or at least have an inkling so that, in addition to learning the subject matter, I can practice reading the appropriately (bad) style of code.

Regards

John

nb. Given that the real exam is currently 88 questions over 2.5 hours, whenever I took the online same tests and exams I have tried to make sure that I do not spend more than the average allotted 102 seconds per question. With Jeanne and Scott's I had no issues and came in under time but ran out of time with EnthuWare.







Regards,

John