Serialization vs Embedded Database for simple standalone application

帅比萌擦擦* 提交于 2019-12-04 06:11:49

问题


Say, I have a pretty simple 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?


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/7421320/serialization-vs-embedded-database-for-simple-standalone-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!