Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!

John Stark

Ranch Hand
+ Follow
since Jul 19, 2011
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
23
Received in last 30 days
0
Total given
7
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by John Stark

Passed Java 7 upgrade exam with 85%.

I prepared with the Oracle tutorial http://docs.oracle.com/javase/tutorial/extra/certification/javase-7-upgrade.html, this website http://java.boot.by/ocpjp7-upgrade/ and of course Enthuware which I would consider essential.

John
6 years ago
The thing that irritates me is that it doesn't explicitly say the writer thread is waiting. And it doesn't say why the reader threads are unable to complete their tasks, it could be any reason?
I have bought my Java 7 upgrade voucher (which is the same as the Java 6 voucher) directly from the Oracle website last autumn for £198.

John
Yes, if you change the type of object returned by the factory, let's say to LuxuriousTexasStyleShoeLeather then you don't have to change the client's implementation as LuxuriousTexasStyleShoeLeather still is-a Leather. However, you have to change the implementation of the Factory as now you have to do


When you invoke the constructor you exactly need to know what kind of object to instantiate.
I am getting confused now. My understanding is that we are talking about the coupling between the product class and Factory. As I understand it the product is the SportsShoe and FormalShoe and the Factory is for example the TexasShoeMakingFactory. The factory does:

and therefore has to deal with a concrete class.


I don't think you need to know the internal details of how a specific TimeZone or a Locale is implemented. As long as you are passing it a TimeZone that is compatible with the Locale, you are good.


Sorry what I meant was using the constructor requires knowledge about how the time zone is implemented in terms of what class is being used to represent a time zone. So instead of java.util.TimeZone some other class like com.mytimeutilities.MyTimeZone could be uses. Instead of using java.util.Locale one could use com.mylocalizationtools.MyLocaleRepresentation.

The reader threads are blocked from reading the File while a writer thread is writing the File. The reader threads are unable to complete their required tasks. Which term best describes the threading issue?

A) Atomicity
B) Deadlock
C) Livelock
D) Starvation

The suggested answer is B) Deadlock.
However, in a deadlock threads in a group of threads are blocking each other and in the given scenario the readers are waiting for the writer but the writer is not waiting for the readers so I would call it starvation.

I emailed them and they say:

Thread starvation occurs when locks are exchanged, not when all threads are waiting for a lock exchange to occur. Think of it this way - starvation is a frequent exchange of locks where some threads do get work done, while deadlock occurs when NO threads get their work done, because they are all waiting.



I think a frequent exchange of locks (preventing the threads from getting the real job done) is a livelock not starvation?
I don't see why no thread can get the work done in the given scenario. It only says while a writer thread is writing the file. Maybe what they mean is the writer thread is waiting for the reader threads to finish and the reader threads are waiting for the writer thread?

Any opinions?

John
Sorry, that is from Kaplan Selftest Software:

What statement is true about the Factory design pattern?

A) A public constructor is required for instantiation.
B) Public overloaded constructors are needed for instantiation.
C) Tight coupling exists between the factory and product class
D) Loose coupling exists between the factory and product class

I emailed them and they say

Tight coupling
still does not exist between the Factory and product classes, because the
factory does not rely on the specific implementation of the product class.
Remember, the factory class only returns an abstract reference. I
understand that some analysts might claim invoking a constructor is part of
tight coupling, but if that is the ONLY thing a class does with another
class, they are not tightly coupled. A tightly coupled class depends
entirely on the implementation of another class.



I don't think tightly coupled means a class depends entirely on the implementation of another class.
I would think how much coupling is introduced by using the constructor depends on the specific example. For example one of the java Calendar constructors is:

protected Calendar(TimeZone zone, Locale aLocale) - Constructs a calendar with the specified time zone and locale.

So using this constructor requires knowledge about how the time zone is implemented (by using the TimeZone class) and how the localization is implemented (by using the Locale class). I would consider that tight coupling. I don't think one can make the general statement 'Loose coupling exists between the Factory class and the product class'.

Another point: If invoking the constructor is not tight coupling how does the Factory design pattern then removes tight coupling (which it is supposedly doing)?

John




I found ExamLab very difficult. I think I scored between 58% and 76% and my final result was 95%.

John
Which statement is true about the factory dersign pattern?

...
C) Tight coupling exists between the factory and product class
D) Loose coupling exists between the factory and product class

Suggestes answer is D).

I would think the purpose of the factory design pattern is to transfer coupling from between the client and the product to between the factory and the product, so I would tend to answer D. Of course coupling
is a gradual thing so one could say the coupling between factory and product is still loose. Any opinions?
Hi,

There is a question about locales where it states to the suggested answer:

results in a locale representing the english language and the United
Kingdom region.

However, when I try

it just prints "en-uk".

However

prints "UK English"

Is this because the Locale constructor expects a ISO 639 alpha-2 or alpha-3 language code or a
language subtag up to 8 characters whereas "en-uk" is a IETF BCP 47 language tag (which can be used in forLanguageTag())?

Many thanks for the helpful replies. It makes much more sense now.

John
6 years ago
Hm, I see. I cannot add anything to the list as it is created with the 'extends' keyword. Is there anything I can do with the reference created in


?

6 years ago
What happens when doing

?

It compiles and runs fine but what kind of ArrayList is actually created?

I don't understand why adding this gives a compilation error:

Thanks,

John
6 years ago
I did the Java 6 certificate (95%) and I am currently preparing for the Java 7 upgrade. I have already read the concurrency bit for the upgrade (Oracle tutorial + other sources) and I have never even heard about Semaphore, Phaser, CountDownLatch, Exchanger or CyclicBarrier