?
Solved

beginning programming question

Posted on 2004-09-22
12
Medium Priority
?
203 Views
Last Modified: 2010-03-31
I am beginning to play with Java and the first application I would like to build will require storeing data inbetween program runs. I figure I could write to a text file, but I was wondering if there might be a better way to approach it? My plan is to have stored data that is read into an array or list at program start up then used while in the program. When I exit the program the data (and any new data added) is written back to the storage area.  No being very familure with Java and wanting to learn, I am really looking more for guidance than anything.

Thanks
0
Comment
Question by:dwanders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 4

Assisted Solution

by:aratani
aratani earned 93 total points
ID: 12129782
Well, if the data you are going to write is simple then you should use a text file with the data and read the data and parse the file on start up.

However, if your data is too complex you could use object serialization to write the object (i.e. the array or the list) directly to the file and read it from there again. In this way, you won't need to parse the file and you could load the object directly from the file.

If you want to store the data, you have to use the files. If you want to understand the format then you have to decide how to write it to the file, and then read it from there. Otherwise, if you don't want to understand how the data is written and just read the data again from the file (without worrying about the structure of the data or the list), then you could use serialization.

You could just use the examples provided here and use it, it is pretty simple,

http://java.sun.com/docs/books/tutorial/essential/io/serialization.html
http://java.sun.com/docs/books/tutorial/essential/io/serializing.html

It is one of the nice features of Java. Hope you'll be on your way,

AJ
0
 
LVL 92

Assisted Solution

by:objects
objects earned 93 total points
ID: 12129786
You could serialize the array using ObjectOutputStream, then use ObjectInputStream to read it back.
0
 
LVL 6

Expert Comment

by:CodingExperts
ID: 12129967
Can you please elaborate the exact problem more.
Thanks
CodingExperts
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 21

Assisted Solution

by:MogalManic
MogalManic earned 93 total points
ID: 12129977
Look into XMLEncoder and XMLDecoder.  They can be used to serialize and deserialize Beans as XML files.  Something like this:
      Person[] people = {new Person(),new Person()};
      try {
            final String fileName="c:/temp/test.xml";
            BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(fileName));
            XMLEncoder r = new XMLEncoder(out);
            
            
            r.writeObject(people);
            r.close();
      } catch (IOException e) {
            
            e.printStackTrace();
      }
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12130504
You can even use a Database to store the data, so to store and retrieve you can use the JDBC. In this manner you do not worry about serialization, etc. Only save and retrieve (the concurrence could be solved by Database itself; if you use file to save and restore, the concurrent access must be solved by your code).

Bye, Giant.
0
 

Author Comment

by:dwanders
ID: 12132511
I will look into the above (serialization etc...), that database approch sounds interesting - In Visual Basic, I have been told it is pretty simple to add an Access database to a program as you data source - would this JDBC be the equivalent of that? If so - where can I find information about writting an app that has a small database (that is accessed only by the single program user - that gets packaged with the program itself) as a datasource?
0
 
LVL 12

Accepted Solution

by:
Giant2 earned 96 total points
ID: 12132542
With JDBC you can execute query (fundamentally).
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12132551
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12132560
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12132583
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12408032
I think a split could be done.
The asker give us no answer about what we suggest.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month10 days, 23 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question