About Question enthuware.ocpjp.v11.2.1768 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
OliviaJohnson
Posts: 7
Joined: Sat Jan 30, 2021 2:04 pm
Contact:

About Question enthuware.ocpjp.v11.2.1768 :

Post by OliviaJohnson »

I don't understand the order of the enumeration.

Code: Select all

noLabel : NO
okLabel : YES
cancelLabel : Cancel 
Is ResourceBundle returning the enumeration in reverse? I thought it would be like this

Code: Select all

okLabel=YES
noLabel=NO
cancelLabel=Cancel  
because okLabel is listed first in the highest priority properties file

Code: Select all

msgs.getKeys().asIterator().forEachRemaining(System.out::println);

noLabel
okLabel
cancelLabel


OliviaJohnson
Posts: 7
Joined: Sat Jan 30, 2021 2:04 pm
Contact:

Re: About Question enthuware.ocpjp.v11.2.1768 :

Post by OliviaJohnson »

Never mind, it's not by ordering in the property file, hashCode, or Comparable.

Code: Select all

c=1
a=1
d=1
b=1
e=1
aa=1
""=1

Code: Select all

msgs.getKeys().asIterator().forEachRemaining(x -> System.out.println(x + ": " + x.hashCode()));

Code: Select all

aa: 3104
"": 1088
a: 97
b: 98
c: 99
d: 100
e: 101
PropertyResourceBundle constructor creates a private "lookup" HashMap wrapping over a Hashtable when constructed. I thought HashMap's iterators do not guarantee ordering, but its interesting how the getKeys() method always return the same output.

I guess knowing the algo for the iterator do not matter to answer this question though.

Sieusc
Posts: 21
Joined: Mon Mar 02, 2020 3:38 am
Contact:

Re: About Question enthuware.ocpjp.v11.2.1768 :

Post by Sieusc »

I don't understand why okLabel=YES in "mymsgs_en_UK.properties" is not printed (as the first line) ?

admin
Site Admin
Posts: 10383
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v11.2.1768 :

Post by admin »

It is just how the values are returned by the enumeration when you do msgs.getKeys();. The order is not guaranteed anyway.

Sieusc
Posts: 21
Joined: Mon Mar 02, 2020 3:38 am
Contact:

Re: About Question enthuware.ocpjp.v11.2.1768 :

Post by Sieusc »

Can you please explain in more detail what Enumeration does and what the flow of the iteration is?

If it is iterating through 1.mymsgs.properties as well as 2.mymsgs_en_UK.properties, then why is is the "okLabel=YES" in 2. not printed?

asi-aal
Posts: 10
Joined: Wed Nov 23, 2022 3:40 am
Contact:

Re: About Question enthuware.ocpjp.v11.2.1768 :

Post by asi-aal »

public abstract Enumeration<String> getKeys();

return an Enumeration of the keys contained in this ResourceBundle and its parent bundles.
Could you tell me what It meant by parent bundles? Is It the base bundle (e.i mymsgs.properties) or mymsgs_en.properties (If existed)?

admin
Site Admin
Posts: 10383
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v11.2.1768 :

Post by admin »

The parent bundle is the bundle loaded just before this bundle. For example, if the chain of bundles that are loaded is a -> b -> c -> d, then c is the parent of d, b is the parent of c, and so on.

Values present in the child are superimposed on the values present in the parent. So, if the bundle c contains key1=value1 but bundle d contains key1=valueX, then key1 will be associated with valueX (instead of value1).

So, now, in this question, as the explanation to option 5 clearly notes:
Remember that if there were another properties file named mymsgs_en.properties also present, then the values of this file would be superimposed on the values mymsgs.properties and then values of mymsgs_en_UK.properties would be superimposed on the resulting union.
Thus, the chain is:

mymsgs.properties -> mymsgs_en.properties -> mymsgs_en_UK.properties

raphaelzintec
Posts: 167
Joined: Sun Apr 21, 2024 10:43 am
Contact:

Re: About Question enthuware.ocpjp.v11.2.1768 :

Post by raphaelzintec »

you guys sure that en_UK search for en_UK?? because on my machine en_UK search only en_GB!!

admin
Site Admin
Posts: 10383
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v11.2.1768 :

Post by admin »

Yes, no reason why en_UK would search for en_GB unless your default locale is en_GB.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 9 guests