Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names, with a first and a last name.
Firstly I will suggest you to change your display name according to the JavaRanch naming policy.
About your question now.
* As you are learning java then you will defiantly study about file handling. Files are a basic way to persist your application's data. You can decide any format in which you will be putting data in your file and when your application starts you can read all this information and keep it in your application in some objects (class you will have to define according to the information you will save). And when your application closes you can write back all this information (which might have been modified) back to the file.
* Another way is that you can use xml files and keep the information in a structured way. Reading and writing information can be done using the xml related APIs.
* But if you want to go a little further you can use a database which might be available on your system, like MS Access, etc or for that matter you can use MS Excel too. You can make a table structure and read and write information into the database. For this you will require to go through JDBC APIs.
Hope this helps
to err is human, but the company policy doesn't allow it!
Joined: May 31, 2006
Thanks for your responce!
I was reading up on XML this morning and considered that as a way to store my data; although I'm thinking that it might be a bit overkill.
I was also considering (originally) to just use comma separated data stored in a file, but I thought that there was a more elegant way to store data that is to persist.
I also considered a DB but because I'm still new to Java I think I'll save the DB option for later by extending my program to read from a server or something.
As far a reading/writing from files is there an elegant format(ie. how does Microsoft address book store their info?)???
I am not sure how MS stores the data in the address book, and you might not want to emulate MS.
Here are two ways for simpler data schemes(ie things that would be overkill with a database). You can either directly implement file IO, which you need to learn anyway, or implement the Serializable interface. If you are asking "What is an interface" you aren't ready for that quite yet. If you have a relatively decent grasp on console IO, either though the Scanner class, or java.io package, file IO should be pretty straightfoward to you. [ June 01, 2006: Message edited by: Rusty Shackleford ]
"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Rusty mentioned interfaces. If you're cool with how those work, you might make a data storage interface that can have multiple implementations. For example, on one project I made a DataStore interface with simple methods like get(key), put(key,value), delete(key), list(). The first implementation used a HashMap in memory, which was enough for me to test some repository functions even though it didn't really persist from one run to the next. The next implementation used flat files and still works plenty well enough. A future one might use another file format or even a database. What's neat is I can swap one out and another in without changing any other code.
There's a cool design concept called "deferring decisions". This interface idea lets you defer chosing a final data storage technique until you have everything else working. And if you thought this had to be one of your first decisions you would not be alone.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Mar 22, 2006
As far a reading/writing from files is there an elegant format (ie. how does Microsoft address book store their info?)???
I am not very sure how MS address book does it. Possibly MS also has a file underneath but they are quite good at hiding things.
Anyways, as I suggested earlier you can decide the format as you like. You can even have multiple files to stored information in a distributed way or have all the information in one file with a pre planned format like
one row having all the information of one person. Just try to keep I/O interactions to a min to increase efficency. As the application starts read the entire file into objects and save them for later use in the application and on close of application write it back to file (repeating myself here )
cheers! mohit To err is human, but the company policy doesn't allow it!
Joined: May 31, 2006
Thanks for all your feedback.....
So I think that I've narrowed it down to CSV or XML as both are supported by java so it should make things a tad easier than coming up with my own format.
If you want to learn Java because you want to become a professional software developer, it is certainly worth the effort to learn how to use databases and JDBC, because databases are very common, especially in business software.
If you're writing an application like a desktop organizer that needs to store data for the application alone (i.e. there are no other applications that need to access the data), you could use an embedded database: a small database that runs "inside" your program, instead of having separate database server software running on your computer. There are a few nice and free embedded databases available for Java, such as HSQLDB or Derby.