This week's giveaway is in the Spring forum.
We're giving away four copies of liveProject: Protecting User Data with Spring Security and OAuth2 and have Laurentiu Spilca on-line!
See this thread for details.
Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring forum!

Mike Gualeni

Ranch Hand
+ Follow
since May 16, 2019
Mike likes ...
Mac IntelliJ IDE Java
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
3
Received in last 30 days
0
Total given
6
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mike Gualeni

Hi there,

Question 57 on page 258 asks what needs to be included in the module-info for it to be a service provider:

Question 56:
You have the following interface in a module named animal.insect.api.



Question 57:
And you have the following class in a module named animal.insect.impl and the service provider interface module from question 56 (from above). What needs to be included in the module-info for it to be a service provider? (Choose two.)



A. requires animal.insect.api.bugs;
B. requires animal.insect.lookup;
C. requires animal.printer;
D. provides animal.insect.impl.Worm;
E. provides animal.insect.api.bugs.Bug with animal.insect.impl.Worm;
F. provides animal.insect.impl.Worm with animal.insect.api.bugs.Bug;

And the answer on page 514 is:

A, E. This module is a service provider. It needs a requires directive for the service provider interface, which is option A. It also needs a provides directive which specifies both the interface and implementation. Option E has both in the correct order.

But A is not right because the directive is:

requires <module> not requires <package>

And question 58 also:

Suppose you have the following class in a module named animal.insect.lookup, the service provider interface from question 56 (from above), and the service provider from question 57. What needs to be included in the module-info file besides an exports directive for it to be a service locator? (Choose two.)



A. provides animal.insect.lookup;
B. provides animal.insect.lookup.InsectFinder;
C. requires animal.insect.api.bugs;
D. requires animal.insect.api.Bug;
E. uses animal.insect.api.bugs;
F. uses animal.insect.api.bugs.Bug;

And the answer on page 514 is:

C,F. This module is a service locator. It needs three directives: exports, requires, and uses. The requires directive specifies the module it depends on, which is option C. The uses directive specifies the service provider interface it references, which is option F.

Answer C is not right because like on question 58 requires directive needs a module not a package! And animal.insect.api.bugs is a package. In question 56 they name the interface module animal.insect.api not animal.insect.api.bugs

And the same problem is on question 59, with answer A,B, but A is not right because in A in the requires directive the package animal.insect.api.bugs is mentioned but it should be the module animal.insect.api!

Good afternoon,

The code in the question is:



but this code doesn't compile, because line 3 has to be;

var map = s.collect(Collectors.toMap(String::length, k -> k, merge));

Or do I have to assume that the necessary static import is available?

Thanks in advance.
Hi,

That's right, I receive also an exception at runtime:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

And therefore the answer should be D instead of C.

Thanks.

Greetings
Michael

Answer of question number 213 on page 119/120 are ACE but the answer E is not right, because both interfaces have 2 private methods:



The answers are:

A. The class fails to compile because of the write() method.

B. The class fails to compile because of the publish() method.

C. The class fails to compile because of the think() method.

D. All of the methods definded in the Alex interface are accessible in the Twins class.

E. All of the methods definded in the Michael interface are accessible in the Twins class.

F. The Twins class cannot be marked abstract.


Only answer A and C should be right. The Alex interface has the private method process() and the Michael interface has the private method study() which both are not accessible in the
Twins class because they are private.

Thanks for your answers.

And I'm sorry, the subject is not "Sybex CSG 11", it should be:

             "Sybex Practice Tests 11"

That's why your failed to find it.
The answer in the book was only:

Suppose Panther and Cub are interfaces and neither contains any default methods. Which statements are true? (Choose two.)

And a picture that indicates that Cub extends Panther

And the answers are:

A. If Panther has a single abstract method, Cub is guaranteed to be a functional interface.

B. If Panther has a single abstract method, Cub may be a functional interface.

C. If Panther has a single abstract method, Cub cannot be a functional interface.

D. If Panther has two abstract methods, Cub is guaranteed to be a functional interface.

E. If Panther has two abstract methods, Cub may be a functional interface.

F. If Panther has two abstract methods, Cub cannot be a functional interface.


And in the book the right answers are B and F. But when I look the question and the answer without mentioning that the methods from Object doesn't count, E could also be right as I sad in my first post. I know a functional interface has only one abstract method (SAM). But when i put String toString(); in the Panther interface it has two abstract methods and it is still a functional interface so E could be right.


Hello,

Why aren't answer B and F the right answers? The Panther interface and Cub could be:



And this compiles and I have two abstract methods in Panther. The Answer E only says:

"If Panther has two abstract methods, Cub may be a functional interface."

And that is true. The answer says nothing about methods from Object?! I now that the methods from Object doesn't count to be a functional interface but in Panther there are definitely two abstract methods and in the above mentioned case,
Cub can be a functional interface. And therefore E should be right not F.

Thanks for explanation.

Michael

Mike Gualeni wrote:Hello

Possibly found an errata. The answer in the book on question 12 on page 410, Chapter 7 Concurrency, is B but it's incorrect.

The method signature is: and throws an Interrupted Exception. And in the question mentioned above, the exception is not caught or declared to be thrown!
And that's why answer F should be correct. If the exception is caught or declared, answer B would be correct.

Greetings
Michael




Okay, I saw this:

Code fragments: A code fragment is a small section of source code that is presented without its context. Assume that all necessary supporting code exists and that the supporting environment fully supports the correct compilation and execution of the code shown and its omitted environment.


But do I have to assume everywhere if an exception is not caught or declared that a main method with the right throws Exception is surrounded'??
Hello

Possibly found an errata. The answer in the book on question 12 on page 410, Chapter 7 Concurrency, is B but it's incorrect.

The method signature is: and throws an Interrupted Exception. And in the question mentioned above, the exception is not caught or declared to be thrown!
And that's why answer F should be correct. If the exception is caught or declared, answer B would be correct.

Greetings
Michael
Hello

First I tried to write the example in chapter 6 "Creating a Service" by myself. But I received an error when i tried to run the program.

Next I got the example from github.com (https://github.com/boyarsky/sybex-1Z0-816-chapter-6/blob/master/) and compiled an packaged it. Then I also tried to run the consumer Tourist.class with:

java -p mods -m zoo.visitor/zoo.visitor.Tourist

I always get the same error as before:

Error occurred during initialization of boot layer
java.lang.LayerInstantiationException: Package zoo.tours in both module zoo.tours.api and module zoo.tours.reservations

As I understand, there is the same folder structure in module zoo.tours.api and module zoo.tours.reservations, isnt' that a problem? Why the example does not work? Can someone help me? Thanks
Hi,

The signature of method merge in the book is:

V merge(K key, V value, Function(<V, V, V> func))

but shoud be:

V merge(K key, V value, BiFunction(<V, V, V> func))


By the way, I like your books, very good explanation. I also read Sybex 815. Thank you.
Hello

I want to learn the objectives for the Java SE 11 Programmer II | 1Z0-816 Exam.

Which books would you recommend to me?

The available books as "OCP Java SE 8 Programmer II Exam Guide" is good but I search something that is more detailed.
Hello

Can someone explain me what I'm doing wrong or is it the class which isn't immutable?

Question: Which of these classes is/are immutable?




Output is:

[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 7, 6]

Answers:

A. Flower
B. Plant
C. Both classes
D. Neither class

Explanation in the book:

14.  B. An immutable class must not allow the state to change. In the Flower class, the caller has a reference to the List being passed in and can change the size or elements in it. Similarly, any
          Class with a reference to the object can get the List by calling get() and make these changes. The Flower class is not immutable. The Plant class shows how to fix these problems
          and is immutable. Option B is correct.

Why is the class Plant not immutable? In my Test class, I wanted to see, if the class Plant is immutable. But the class Plant isn't immutable, it is mutable! I can change the values and add() a new value!
Why? Have I made a wrong example? I know an ArrayList and a List is mutable, is that the problem?

Can someone fix my example to make the class Plant immutable? Should I have to return a Collections.unmodifiableList()?

Thanks for some help.
Hi,

Another errata in answers to review questions 9 on page 515:

"Option C is incorrect because while CharSequence is a subtype of String, the generic type parameters must match exactly."


CharSequence is not a subtype of String, it's vice versa -> String is a subtype of CharSequence!