• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ResourceBundle use

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Pieter Jacobs
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Pieter Jacobs
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

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

Enjoy your weekend - or what's left of it :-)
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
    Posts: 88
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Roel,

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

    Thanks, I also like the second option.

    Enjoy your weekend,
    Pieter
     
    please buy this thing and then I get a fat cut of the action:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic