Reputation:
I've been asked to "write a file to disk in a format that is easily readable by other applications. There is no requirement for the file to be human readable". The data to be written to file is a combination of integer, string and date variables.
I can't quite figure out what the aim of this question is and what the correct answer should be.
What are the core considerations to be made in order to write a file to disk in a format that is easily readable by other applications (using the simplest possible method).
No this is not homework.
Upvotes: 2
Views: 210
Reputation: 234817
This is a pretty vague requirement. If the other applications also written in Java, then Java serialization may be the best approach.
EDIT: @leftbrain — In answer to your comment, I think I would lean toward XML; it was designed to support basic interoperability among applications. The three kinds of data mentioned (integer, string, and date) can generally be represented exactly with no special tricks and there is good support for XML processing across most programming languages. However, each data type (in the abstract) can present challenges. I would have asked the following:
Upvotes: 2
Reputation: 533590
What the interviewer is looking for is to find out what experience you have in this area or what you might consider in implementing such a solution. Its and open ended question which has no right answer, it rather depends on the requirements.
Some suggestions use serialization of a data structure. Here a few http://code.google.com/p/thrift-protobuf-compare/wiki/Benchmarking
Use an SQL or NoSQL database. Here are some NoSQL databases. http://nosql-database.org/
Write the data to disk using DataOutputStream (IO), heap or direct ByteBuffers or memory mapped files. This can work well for simple cases like the one suggested in the question. As you requirements get more complicated, you might consider other options.
Upvotes: 1