File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes What is this 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 "What is this Properties File?" Watch "What is this Properties File?" New topic
Author

What is this Properties File?

Seetharaman Iyer
Ranch Hand

Joined: Jun 25, 2010
Posts: 35
Hi,

From Req Doc :
Your programs must not require use of command line property specifications. All configuration must be done via a GUI, and must be persistent between runs of the program. Such configuration information must be stored in a file called suncertify.properties which must be located in the current working directory.


1. What kind of configuration must be done/stored in properties file?
2. Is it mandatory to use properties file ?
3. Current working directory means? - I know user home directory and the way how to access it ("user.dir"). How to get current working directory?
Example : my runme.jar is located in the path : C:\Testing\SCJD\runme.jar. In which directory, properties file will be stored.
4. Do I have to include suncertify.properties in the deliverables (submission jar)?
5.
All configuration must be done via a GUI
means ? - Each property in the file must have associated field in GUI? Example: server location text field for the property "server.location"
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5597
    
  15

1/ This will be an interesting thread about properties file.
2/ all "musts" in these sentences, so yes it is mandatory. (violating a must requirement = automatic failure)
3/ I used System.getProperty("user.dir"); to get the location to store my properties file
4/ No, you should not package it in your submission.jar nor runme.jar. The 1st run the properties file should be created at the desired location
5/ All the properties which are stored can be changed in a GUI.


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

Joined: Jun 25, 2010
Posts: 35
Thank you so much Roel for your timely help.

Just three more questions.
1. How to read the properties file? Reading properties file is just like reading other normal text files by using RandomAccessFile/BufferedReader?
2. I planned to include following fields in the properties file.
a) "server.dbpath"
b) "server.port"
c) "client.ipaddress"
d) "client.port"
e) "standalone.dbpath"

In "server" mode --> properties a and b will be used for reading/updating the settings
In networked client --> properties c and d will be used for reading/updating the settings
In "alone" mode --> properties e will be used for reading/updating the settings
My assumption is, launching the application in different mode on the same machine will not affect other mode settings. Is this perfect?

3. Which option is good? a) Hard-coded port number or b) as per above - explicit port number setting. I prefer option b as attempting to use the taken (already in use by other application) port number will stop the user from proceeding further (I think it will throw the error like "address already in use - can't bind"). This explicit port number setting will enable the user to choose another free port number.

Thanks,
Seetha...
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5597
    
  15

1/ Maybe have a look at the Properties class.
2/ I include just 3 properties: db path (used for network server and stand alone client), port (used for network server and network client), server address (used for network client).
3/ answered in 2/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is this Properties File?