wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Question about properties file 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 "Question about properties file" Watch "Question about properties file" New topic
Author

Question about properties file

Olena Golub
Ranch Hand

Joined: Jan 17, 2005
Posts: 113
Hello,
Do I understand my assignment (UrlyBird) about properties file correctly?
For example if the properties file doesn't exist, the Configuration dialog will appear. The user enter the information depends of the startup
mode (database location, or IP or Port). Than the properties file will be created and all entered information from the user will be saved.
If the user starts the second time the application (server, or client, or the standalone) the programm looks if the properties file exists. If
this exists the application will be started with the parameters from the properties file without the Configuration dialog .
If some properties values are not defined. The Configuration dialog appears.
The user can modify this properties file also from gui:
for Standalone/Remote Client the properties can be changed in the main GUI, where I make the booking or search.

for Server the properties can be changed in GUI where I have only one "stop" button.

How do you think is it "as right as rain"? Did I understand it correctly?

Thanks a lot for your comments!
Regards
Olena


SCJP 1.4<br />SCJD 1.4 (in progress)
David Sham
Ranch Hand

Joined: Apr 19, 2005
Posts: 61
My understanding of the properties file is that it is to be used for any GUI configurations associated with your client (or server also). However, I am using it to store the database file locations (for the server and standalone client) and remote hosts and ports (for the remote client). I would imagine that you should show a startup dialog of somekind for the database location or remote server regardless of whether the properties exist in the properties file or not. This way the user can change these properties configurations if desired before starting up. Of course changing properties from the client GUI (or server) would be recommended too.

One question I have: my specs say that the properties file "must be located in the current working directory.". Would that be the directory from which the program is running? If so, that sounds like it should be in the suncertify.db package. Does that sound correct?

Any input is appreciated. Thank you.
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
Olena,

You are right as rain! That is almost exactly the same way I implemented mine.


“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
I would imagine that you should show a startup dialog of somekind for the database location or remote server regardless of whether the properties exist in the properties file or not.

I actually implemented mine the same way as Olena described, and did just fine. There is nothing, however, that says you cannot do it your way though. I have implemented both in real world situations. I would recommend filling in the dialog field with information from the properties file though... it makes it much easier on the User.

One question I have: my specs say that the properties file "must be located in the current working directory.". Would that be the directory from which the program is running? If so, that sounds like it should be in the suncertify.db package. Does that sound correct?

The current working directory is the one that you executed the application from, i.e. the directory you are in when you type "java -jar runme.jar". When you submit your assignment, it must be in jar form. Therefore you would not be able to write to a datafile that is in the suncertify.db package. Also remember that you cannot require that the properties file exists at startup, as assessors have been known to remove it...
David Sham
Ranch Hand

Joined: Apr 19, 2005
Posts: 61
I got it, I think. Should the properties file be put into the java classpath? The classpath would be retrieved as: Sound right, or am I way off? Thanks.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11465
    
  94

Hi David,

Should the properties file be put into the java classpath?


No. Take a look at Paul's reply above.

Perhaps an example might help:

In the example above, the current working directory is c:\temp. The runme.jar file is in a different directory (c:\scjdProject), and we cannot tell from that command line where the database file is - it could be in third, completly unrelated, directory.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Wei-ju Wu
Ranch Hand

Joined: Feb 16, 2005
Posts: 147
If you create a File with a name only, this would be represent a file within your current working directory by default. If you explicitly want to know your current working directory, have a look at the java.lang.System documentation, specifically under getProperties(), it is called "user.dir"


"The UrlyBird catches the certificate. And he's gonna FlyByNight"<br /> <br />SCJP 1.2/5.0, SCJD, SCBCD, SCWCD, SCEA
David Sham
Ranch Hand

Joined: Apr 19, 2005
Posts: 61
Thank you both for your replies. Yes, I just learned from a friend that all you need do is instantiate a FileInput/OutputStream object with the filename and the first place it will look is in the current working directory. That's it. Then use that Input/OutputStream object to load/store your properties hashtable. I also just missed the user.dir key in the java.lang.System specs in the API. It was late last night and I was too tired to see it I guess. My code should actually be more simple now. Thanks a lot!
 
GeeCON Prague 2014
 
subject: Question about properties file