Preferred data format for user data in Java applications?

I am currently developing a desktop application in Java that stores user data, such as bookmarks for ftp servers. When deciding how to save this information, I ended up using xml, simply because I like the way xpath . I was thinking about json , which seems easier.

What is your preferred way to store data in java applications (in general) and why? What about java-persistence, does it have any advantages worth noting? And how much does the size of user data matter? It is not always possible to store data in a database (or preferable), and in my experience xml does not scale very well. Let me know what you think!

No one has mentioned me yet, which amazes me. There is no situation when this is suitable?

+4
source share
6 answers

Everything that works gives you good performance and requires the least amount of code.

Java serialization is easy. Be quick if you do not have large object schedules. This may not work if you ever want to interact with another language or want the file to be readable / editabl. It can be fragile.

XML refers to multilingual interaction, can be read and edited by people. If you use Java, Jaxb is very, very easy and fast. If you need to save a lot of settings, SAX / StAX may be required. You might want to use the DOM / JDom in very strange circumstances.

If there are many settings that you want to save and execute the query, the embedded SQL database is an option. I recommend H2.

+5
source

Sometimes it’s just enough to use property files.

A properties file is a text file consisting of key / value pairs. The java.util.Properties class is used to interact with property files. However, this is not good for storing lists of things, because all key / value pairs.

+5
source

It is impossible to say that I prefer "generally". Even in one application, I can have several different ways to serialize user data. Take a computer game, for example. I want my game settings to be stored so that I can edit them using a text editor. I want my licensing data to be stored so that it is accessible worldwide. I want my records to be saved so that no one can edit it effectively. I want to save the saved state of the game so that reading and writing are very fast. These four different requirements can lead to four different solutions in one application.

+2
source

There are two aspects:

  • If you want to quickly implement it using an RDBMS, use a built-in DB such as SQLite. This is used by many desktop applications such as Firefox .

  • If performance is a problem, use inline key-value pairs .

+2
source

We use XML, if we do not mind the user customizing the data. For more complex data, we use SQLite. Here you can find the Java implementation,

http://sqljet.com/

+1
source

Whatever format is used to create the file, it is recommended to save the file in the user's home directory:

 String userHome = System.getProperty("user.home"); // "/home/myusername" 
+1
source

Source: https://habr.com/ru/post/1311784/


All Articles