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 6 years ago.
Improve this question
I have a list of objects which get created by a factory class and for the time being I want to limit the list size to 10 objects. I also need to maintain the list through out the program as multiple classes will be referencing its values. I don't want to create it as a singleton and im not happy about having a master class maintain it, so is there another way? (Best Practice)
For setting the max size you can refer to this post here Any way to set max size of a collection?
Not sure what you mean by "maintaining" the list though. There is no way (that I know of) to make that list accessible to all classes without having it in a "master class". The only other option is passing it through functions.
Related
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 2 years ago.
Improve this question
I have a requirement where I read string from huge file and process it in HashMap. I want to throw exception when HashMap size is > 5GB. How do I set the max memory size of HashMap?
You subclass HashMap and override methods to keep track of what is allocated and freed, and throw the exception yourself.
However, be aware that determining how much memory an object occupies is itself a significant task... how deep do you go if the object contains references to other objects?
This is a non-trivial problem of deciding what you mean and what you want to track. There is no one-size-fits-all answer.
And, as suggested by #ModusTollens in a comment, this is likely an XY Problem.
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 5 years ago.
Improve this question
I understand we can do this with file input and output, but why would we want to do this?
It is simply called persistence.
You nailed it: you want to be able to store information (for example after intensive computations) in a way that survives the lifetime of the current JVM process.
In that sense serialization is a (poor) version of database storage.
But of course, that comment is correct: this does not prevent the creation of objects. It is a mechanism to resurrect previous state into "new" objects.
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 5 years ago.
Improve this question
I'm new to using a database, specifically MySQL. I'm creating a web application for class in which you can look up the name of a book and it'll display the summary of the book. My question is should I send a query to the database that collects all of the books' data on initialization and put them into a HashMap inside a manager class for lookup or should I use a query each time to lookup a specific book information?
It depends on the data transport time I would say. If your average query time times the number of request goes faster than a script to put everything into a HashMap, use queries. Otherwise, use a script that collects everything and puts it into a HashMap.
But if you have thousands of rows, you should use queries, because otherwise you will use too much RAM.
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
what is the best type to store data from csv format file, where is 150k records(lines) where each line has 9 columns(fields). After initialize my type with these data i need to do some operations on it, like add record in specified line, or add/change some data in some field. Also i need to compare data between themselves. Thank for help!
The best type to use is an ArrayList of a domain object. The domain object has 9 properties.
In other words: don't make it generic, make it specific for your problem. Then your code will be more readable and type-safety helps you when you create the functionality.
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 8 years ago.
Improve this question
There are several methods to create Instance in Java
(Different ways are new operator, cloning, reflection and DE-serialization etc)
So among them which is the fastest of all ?
In such a case fastest means which one of those executes less operations before actually allocating the memory for the object. It is easy to determine that new is the fastest among those because it doesn't bear the overhead created from the others such as clone etc.