Java: small key/value persister [closed] - java

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I need a very lightweight and persistent key/value-store in Java.
The amount of data is very very low and it should be very simple (getter and setter and all can operate on strings).
So I think of using some small NoSQL-DB or even giving some integrated collection a serializer/deserializer to the filesystem.
But I think NoSQL is a overkill and I hope a persister also exists for such a simple requirement.
Whats the best approach here? Any ideas?

You can either implement your own thing if it is a simple key-value string. (Have a look at Java's Properties class too in case it suits your requirements).
If your requirements are slightly more complex have a look at the embedded lightweight databases you can use. Maybe BerkleyDB might work for you. There are quite a number of others if you do a bit of search.
Also think about what you actually need to do with the data. Do you need to query it (so it needs to be indexed?) or do you just want to load it back all into memory? (in which case using a simple JSON or YAML text format would also suffice.)

Most Map<String,String> can be serialized. So for example look into https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html
there you find Serializable. Under that point information to help yourself solve the Problem.

Related

Using SQLite or a File [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I am new to Android development and I am trying to make a Trivia application.
I need to store the data relating to questions somewhere and I am not entirely sure where to store it.
I plan to have multiple people playing so I need each person to have the same questions.
Basically I planned to have a list of categories and within each category I had question objects.
The question objects contained information regarding the question such as the answers and question itself.
However, if I use a database, I believe none of this would be needed due the questions being stored in tables which would represent categories.
In terms of speed what would be better:
to store it in a database
or to read from a file every time the application is loaded and store the data within a data structure?
You almost certainly want a database. Databases are made for fast search and easy insertion/deletion. There's really no advantage to having a file and doing in memory parsing each time.
Aside from performance benefits, here's a simple list of advantages of using SQLite rather than flat file:
You can query items as you wish -- don't need to load all of them and
select which ones you need.
Record deletion is a much less painful process. No rewriting of whole
files into wherever.
Updating a record is as easy as removing or creating one.
Have you ever tried doing cross-referencing lookups on a flat file?
Just.Not.Worth.It.
To summarize, it's every advantage a Database has over a text file.
Answer by josephus

Creating my own Lists and Maps data structures [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
For practice I want to make my own lists and maps (like ArrayList, HashMap, HashSet etc.).
My goal is to have it as small and flexible as possible while still maintaining good performance. (long road...)
I have some questions:
1)
Unlike the sun, I don't have to take backwards compatibility into account.
So the first thing I wonder, is there any good reason to keep add and put?
Why not just one?
If I would name put > add would this give problems / complexity / unclearness down the road?
2)
Are there any languages known to have really good data structures? (For example, they could be really smart to avoid a concurrency exception).
3)
As last more a request then a question, if you have any tips our vision of how things could be done different then please post them.
There is no duplicated methods, Collection's have add method that returns a boolean, Map's have put method that returns type associated to Map.
There are plenty of examples of data structure, the point is, ¿what you need your data stucture do best? Avoid concurrency? sort? be fast? store securely?
The examples you need are directly in Java source code:
SOURCES
List
ArrayList
HashMap
and so on....

should I use distributed executors or mapreduce in hazelcast [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I need to run some calculations on a distributed map. But I cannot decide which approach to take.
My calculations will result in a map data structure. where the results will be mapped to their keys. think of it as a word count example. where word is the key and occurrence count is the value.
I have looked into both solutions and as I understand, map reduce fits best in this scenario but i want to keep things simple. and i also cannot see why this is not possible with distributed executor.
Both options are possible. Before we had the generic mapreduce framework people build solutions like this using the ExecutorService implementation.
At the moment, it'll change in the near future, the mr solution doesn't offer a way to write to an IMap directly, so all results are send to the caller first and he would have to store it then.

Java versus XML&Lua for storing voxel/block types [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
So, I want it to be very easy to create all the entities of my game and for other people to come in and do the same. I was thinking I could just let the users/myself create an XML sheet the stores all the properties of each block (Like a Terraria or Minecraft voxel) and add Lua scripts that are referenced in the XML for additional functionality of any of the blocks.
I'm starting to think It would just be easier to let the user create a JAR file full of classes for each block. And then that JAR file could easily be used to get all the blocks. It'd just be interesting to reference all the blocks by a block id without storing all the classes by ID. Or I could give each class a static id. But that's not important.
Okay, so my short question is what are the pros and cons of storing all the the different types of blocks as classes versus in an XML sheet with Lua for additional functionality?
UPDATE: It looks like I'll be using pure Lua! Looks like an interesting and effective way to do it!
A limitation of the JAR approach is that your data would need to be compiled before it got used. With XML/Lua the data gets read/interpreted at runtime.
A third option that you did not mention is using straight Lua tables instead of XML. This lets you load the data with a simple "require", "dofile" or similar instead of needing to use a XML library as well.

Which is the fastest way of converting an Object to a stream of Bytes in Java? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have an object which I want to convert into a stream of bytes and then to operate on it. I don't want to serialise the object, but just to convert it. I have read this article, where Java Unsafe class is used and the conversion is very fast. However, is there any other fast solution for this?
Fast Convertion is possible. You can use GSON lib. then get it to json string. Use the string as per your requirement. Hope this helps.
There are a number of libraries in development to do what you suggest. I believe all of them are discussed on this forum. https://groups.google.com/forum/#!forum/mechanical-sympathy which may also have many topics which may interest you.
In short you can do it using Unsafe, or a library which uses it. In fact I have one of my own, but again it is in development.
For the effort involved this will only make much of a difference if you have many GB of data. At this point the reduce GC times and reduced size of the heap are the main advantages, on saving a single de-reference.

Categories