开发者

Serialization vs Embedded Database for simple standalone application

开发者 https://www.devze.com 2023-04-05 02:29 出处:网络
Say, I have a pretty simp开发者_开发技巧le Java application that needs the way to store some user settings. XML is not a really good solution, since I want to store them in binary form. So, what would

Say, I have a pretty simp开发者_开发技巧le Java application that needs the way to store some user settings. XML is not a really good solution, since I want to store them in binary form. So, what would be the best solution in this case, embedded database (such as Apache Derby) or just plain old serialization?

I know that these are two completely different things, but both allow to persist some application state. So what would you chose, and why?

Edit

As far as storing simple user preferences go, .properties or xml files are fine, I agree with you. But what if I want to store passwords, or some application-specific data?


User settings are typically stored as

  • properties, using the properties file format
  • properties using the XML format
  • preferences, using the Preferences API. This has the advantage of storing and reading user and system preferences for you, without having to think about where to store them, etc. See http://download.oracle.com/javase/1.4.2/docs/guide/lang/preferences.html


As Apache Derby is an embeddable relational database, it makes sense to use it for storing and manipulating relational data. Using an embedded db for persisting a few user settings only is a bit overkill.

If it were me, I would use a simple key/value pair serialization for persisting user settings.

0

精彩评论

暂无评论...
验证码 换一张
取 消