Win a copy of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests this week in the OCP forum!

Mikalai Zaikin

+ Follow
since Jun 04, 2002
Forum Moderator
Mikalai Zaikin currently moderates these forums:
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

Recent posts by Mikalai Zaikin

lord uhuru wrote: will give more time, and study more before the retake, roughly 2 weeks. I will make a formal application for extension at work.

Two months (or at least 1) would be better, if you can apply for such extension. Just my 2 cents.
Hi Lord Uhuru,

Your study sources look good, exactly what you need to pass the exam successfully.

I recommend you just spend more time on preparation and not rush in exam again, especially after 5 days.

I believe there is some misunderstanding about 5 days, was it a condition of free retake policy from Oracle? If yes, then it does not make sense, how a failed person can prepare so fast. 8((
I would personally take 1Z0-817, it seems less stressful 8-)

On the other hand, if your goal is to learn as many as possible new Java 11 areas -- take 1Z0-819, but be prepared for a tough exam
Hi !

It depends on what you is your ultimate goal:

- If you want just print names, use code proposed above by Jj:

- If you want to manipulate with distinct Winners later you need another approach because the map() operation will map from Winners to String and your Winners instances are lost.
In case you want to filter by distinct name and keep Winners in the stream, use a workaround described here (use distinctByKey custom predicate and filter stream by it):

3 weeks ago
Hi !

The Stream.distinct() uses equals(Object o) method to eliminate duplicates. It's hard to tell if Winner class implements own equals(Object o), based on the code provided, so it's hard to tell why your code works not expecting.

Further reading:
3 weeks ago
Let me explain.
When you use parse or of, the code creates every time a new instance of the object, i.e. it uses "new" keyword and call constructor.
So, the == always returns false for any 2 objects created with new keyword.
Otherwise, it would be possible to hack any application: backend code created "account" and you created an account with "new", and it happened that your account points to the server-side account, and you have full control.

You can easily track the source code of LocalDate, for example "of" factory method:

So, for any 2 LocalDates created with "of" comparison with == will give false (because every time new object created on the heap with the new keyword).

Needless to say yhat equals() method overriden for LocalDate and compares logical content, so for those it will be "true"

Clemonte Johnstone wrote:

Mikalai Zaikin wrote:Clemonte, may I guess the compiler complains because of the empty body?
Can you add inside the curly braces "throws new IOException();" and see if it helps?

This code absolutely correct. You may not throw in sub-classes or implementing classes more "wide" (or more "generic") exceptions.
1. You may throw more "narrow" exceptions
2. You may just not throw anything (missing "throws" section

SIDENOTE: I wrote incorrectly above, I mean "throw", not "throws" inside curly braces block 8(
Another option is that SampleClass refers some "custom" IOException from a different package.

It's apparently a bad practice (compare: java.util.Date v.s. java.sql.Date), but might it happen that SampleClass uses (and imports) some com.mycompany.IOException, and MyInterface refers by fully qualified name
Clemonte, may I guess the compiler complains because of the empty body?
Can you add inside the curly braces "throws new IOException();" and see if it helps?

UPD: I mean "throw", not "throws" 8(((

Vimugdh Lall wrote:You're right Mikalai. I was trying to say the same thing. Which is why the line of the book that I quoted in the first post is confusing regarding the no-args constructor. As long as there is a parameterized constructor present, I must always call that constructor and not the super() constructor in the child class, even if the parent class doesn't have a no-args constructor.

The authors assumed a different idea, IMHO.

When they said: "must start with an explicit this() or super()" they mean "must start with an explicit this(), this(...) or super(...)"
They wanted to emphasize (again, IMHO) that the developer now needs explicit call, and they (IMHO) did not mean literally super(), but super(XXX);
Hi !

You cannot call super(); if parent class has no-args constructor (implicit or explicit).

Might this code example be helpful?

Congratulations R Ranjan !

Congratulation Amir!

Great job!