aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes ResourceBundle use Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "ResourceBundle use" Watch "ResourceBundle use" New topic
Author

ResourceBundle use

Pieter Jacobs
Ranch Hand

Joined: May 20, 2009
Posts: 87
Hi again,

Where is the best place to put all the ResourceBundle code (for getting the Magic Cookie)?

I have put the code into the "Data" class' constructor, but after having a goodnight sleep now, I thought that idea actually sucked?

Thanks and enjoy the day!
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

Hi Pieter,

ResourceBundle-code for getting magic cookie I thought ResourceBundles where used to let your program support different languages in an easy, simple way.

Because i18n is not required by the instructions, I didn't add this to my program.

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Pieter Jacobs
Ranch Hand

Joined: May 20, 2009
Posts: 87
Hi Roel,

Sorry, my mistake, I was thinking about what to right instead of concentrating :-)


I am actually using the ResourceBundle for getting the Magic Cookie from a Properties file which I then use to check if the Magic Cookie I'm getting from the DB file corresponds.

Thanks for the reply though!

Enjoy.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

Hi Pieter,

I advice you not to use ResourceBundle for that purpose. I think you will certainly lose some points because you are abusing (a class from) the Java API, while there is another class java.util.Properties that's more suitable for the job.

And as a final remark I think you are just overcomplicating this. How I handled it: the magic cookie is verified against a hard coded value (in my Data class) and I justified that approach in decisions document.

Kind regards,
Roel
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2267
    
    3

Howdy, y'all.

Yes, as my buddy Roel said, that's the purpose of a ResourceBundle. Another thing is, you'll have to save values in the suncertify.properties file, and as far as I know, you won't be able to do that using a ResourceBundle, which is just as read-only. Thus, I created a small component that deals with the .properties file, which also uses java.util.Properties class.

Some people choose to read the database schema at runtime, which makes me think... how are you going to know if the first value present in the .db file is the correct magic cookie value? I created an interface called Constants, wich my Data class also implements, and I opted to put the value of the magic cookie there, and when reading the .db file, I verify if the value found matches the value of my Constants interface.

I know some people just ignored the magic cookie and justified it. Since the assignment does not provide much information about this value, I assumed that the value that appears in the .db file that was provided to me is the correct one, and that is the value that I informed in my Constants interface.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Pieter Jacobs
Ranch Hand

Joined: May 20, 2009
Posts: 87
Hi guys,

Thanks a lot man, I really appreciate the replies!!

Enjoy your weekend - or what's left of it :-)
Jarek Losice
Greenhorn

Joined: Nov 07, 2008
Posts: 25
By the way,

I was just about to begin label externalization to ResourceBundles. Right now I've got all the literals (labels, questions, all the texts) hardcoded directly in *.java files.
What do you think? Is it a good idea to externalize all of these into ResourceBundles or maybe it can just stay the way it is - hardcoded?
Maybe someone who already passed SCJD can help us out?
Thanks,

Jarek.


Sun Certified Java Programmer for Java 6
Sun Certified Java Developer
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

Hi Jarek,

It's easy: use of ResourceBundle is not a "must" requirement, so you don't have to do it, just hard-coded values will be enough. I decided to create a class defining all strings used in the GUI (captions, labels, error messages,...) in static final declarations. This will make localisation (i18n) easier later (if decision is made to add it).

Kind regards,
Roel
Jarek Losice
Greenhorn

Joined: Nov 07, 2008
Posts: 25
Roel De Nijs wrote:Hi Jarek,

It's easy: use of ResourceBundle is not a "must" requirement, so you don't have to do it, just hard-coded values will be enough. I decided to create a class defining all strings used in the GUI (captions, labels, error messages,...) in static final declarations. This will make localisation (i18n) easier later (if decision is made to add it).

Kind regards,
Roel


Thanks!
Pieter Jacobs
Ranch Hand

Joined: May 20, 2009
Posts: 87
Hi Roel,

Do you actually specify the database schema in your suncertify.properties too, or do you hardcode the recordLength and fieldLength*s too.

I have started specify all these values in my properties file, but I think I'm definitely over-complicating this!

Thanks bud!
Pieter
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

Hi Pieter,

Don't put the database schema in your properties file! That file is just meant to store the choices of the user (server address, database file location, port number).

You have 2 choices:
  • hard-code these values in some java class (or interface)
  • read the schema dynamically and store the information you need


  • I implemented the second one, because it gives you more possibilities for future enhancements. But also with the first one you'll pass the assignment.

    Kind regards,
    Roel
    Pieter Jacobs
    Ranch Hand

    Joined: May 20, 2009
    Posts: 87
    Hi Roel,

    Thanks a lot for the (very) quick feedback !!

    Thanks, I also like the second option.

    Enjoy your weekend,
    Pieter
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: ResourceBundle use