This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!

Paul Nijssen

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

Recent posts by Paul Nijssen

Hi,

Thanks all for the quick responses.

Rob Spoor gave me the clue I was looking for; I forgot the () -> in the line where I create the supplier....

About using the complicated way to create a collector: I am studying for OCP, and I try to get used to use the functional interfaces.  So, the creation of the collector myself was just an exercise and has no practical goal.

Best regards,
Paul
5 days ago
Hi,

I have a question about the use of the collect method of the Stream class. For learning I have created a stream with some Person objects, and I try to convert this stream to a List using the difficult way (not using a predefined collector). So I have create the following code first:

This works fine so, to make this code a bit smaller, I rewrote it as follows:

To me this looks functionally the same as the first block of code but the compiler complains about the collect, add and addAll methods. So, I rewrote this sample to explicitly tell the compiler the type of the variables of the lambda's:

Unfortunately, this code also doesn't compile. The compiler still complains about the type of the two BiConsumer arguments. To me it seems that it must be possible to implement the collector this way. Could someone explain what is wrong with this code?

Thanks in advance,
Paul
Hi,

There are situations using wildcards that are confusing me a bit... So, I have a question about the following code:

For list1 I can understand that that adding an instance of X is not allowed.
For list2 it is not clear to me. First I declare a list that might be a list of type Y or a super type. Then an ArrayList with an explicit type X is constructed. So, why is it not possible to add an instance of X to that list (list2)? The compiler might "know" that list2 is an ArrayList of type X.

Best regards,
Paul

6 months ago
Thanks for your quick response Campbell.

In case of using the method with the List<T> argument I can call the add method for the list, but for the method with the List<?> argument I can not call the add method.

When calling add on List<?> the compiler shows some intriguing error message:

The method add(capture#1-of ?) in the type List<capture#1-of ?> is not applicable for the arguments (T)


So, it seems that the generic type T could not be used to add to the List<?> list. Checking my study guide shows that unbounded generics are immutable so it might be logical that you cannot call add on the List<?> but the error message don't give me a real clue.

I am still a bit confused about when using List<?> and List<T>....
7 months ago
Hi,

With respect to generics: why should you use an unbounded wildcard?

For example, this method:

seems to act the same as this method:

So why and/or when should I use List<?> in the place of List<T>?

Best regards,
Paul
7 months ago
Hi,

I am studying for OCP using the Sybex Study guide. At the end of chapter 1 (page 32), about static nested classes, if found the following sentence: "The nesting creates a namespace because the enclosing class name must be used to refer to it". That sounds clear to me but what do they mean with namespace here? I know namespaces from .Net and XML, but are namespaces somehow also used in Java?

Best regards,
Paul
9 months ago
Hi,
On line 3 variable a is first cast to byte and then the add takes place. Since the result of adding a and b is promoted to int this will not compile.
At line 4 you first add a and b and the result of this is then cast to a byte.
Hi,

I used the Sybex Study Guide written by Jeanne Boyarsky and Scott Selikof and using this book i passed the exam in one try. The book covers all the necessary topics and is written very clear. Next to the book you also get a lot of online questions to practice.

Best regards,
Paul
Hi,

I am studying for OCP using the Sybex study guide. In the part Working with Enums in the first chapter, at page 20 is written "...enum is a type of class...". So is was a bit surprised that a private variable within the enum is visible outside the enum, like it is public. Please, see the code below.
When using the enum i am able to see the value of the private variable named "info" and (if not marked final) I can also change this value from outside the enum. It seems the private modifier has no effect on the visibility of this variable outside the enum-class. To me this seems to breaks encapsulation, in a normal class this is impossible. Am i doing something wrong or is this normal behavior for an enum? If so, what is the reason for this behavior?

Best regards,
Paul
10 months ago

Campbell Ritchie wrote:. . .  
No, it isn't. Once you let objects of that class out, any other code receiving them will think it is allowed to alter those pubic fields. That is an inherently unreliable design.


But, if i have only a private field and a getter and setter for that field, what is the difference between changing the value of the private field by a setter and changing the value of a public field directly?
11 months ago
Hi all,

It seems that the I prefix is not common i understand now. To me it would be nice to have an indication if you have to do with an interface or a class because you can not instanciate an interface. But, when i am thinking of this, this would imply that you also have to prefix an abstract class... So, no prefix for an interface. ;-) But the naming using ...Impl does not seems to be very helpfull to me, maybe it is better to ad someting that describes what it is. So List<> (interface) and CustomerList (class) might be a solution.

Thanks for the responses.

Best regards,
Paul
11 months ago
Hi,

Suppose i need a class which only holds some data, so there are no methods in the class to operate on that data. Such a class could, for example, look like this:

That is a lot of code so i am wondering if it in this scenario is accepted to use this:

Since there are no methods to operate on the data, to me this gives the same result as the "encapsulated version" of the class (although this might not be really OO).

What is a common approach in Java programming for this? Are there conventions for this?

Best regards,
Paul
11 months ago
Hi,

I'm coming from C# and there is an interface prefixed with the uppercase I (e.g. IReader), and also the interfaces in the framework are prefixed with an I (e.g. IEquatable). In Java the naming conventions seems to be different. I don't see the prefix in the interfaces found in the API. So List is an interface but ArrayList is a class; it is not possible to see from the name if you are dealing with an interface or a class.

What is the common way in Java to name interfaces?

Best regards,
Paul
11 months ago
Hi,

I am preparing for the 1Z0-808 exam using the oraclestudy exam test-questions. In these questions i found a question about InternalError, OutOfMemoryError, StackOverflowError and UnknownError classes. To learn Java i used the Sybex book (written by J Boyarsky and S Selikoff) and i thought that only the StackOverflowError is covered in this book. Does anyone know if is have to know the details about InternalError, OutOfMemoryError and UnknownError for the exam?

Best regards,
Paul
Hi,

I've a question about garbage collection, this is a question from a test-exam. The exam question is how many object are eligible for GC after the last line of code, the code is as follows:

String[] balls = new String[1];
int[] scores = new int[1];
balls = null;
scores = null;

The right answer must be two but to me it seems that the answer is four: there are two objects with a reference to the array (balls and scores) and there are two arrays with one element each (String[1] and int[1]) so another two objects. I don't see why the right answer must be two...

Does anyone have a clue?

Best regards,
Paul
11 months ago