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 8 years ago.
Improve this question
So I've been giving a project for school and was just hoping for reassurance towards the decision making I do.
My java skills are extremely basic and need to improve drastically soon! I just seem to be getting nowhere atm :P
Anyway, back on topic.
My first task is to create an interface directory that can do the following
Keep in mind this is assessed work therefore please don't provide answers. I have enough time to complete this since I've started early!
My initial approach for going about this task is using a Linked List. I don't know what you guys think about that? I may be completely wrong but based on the topics we have covered in School. LinkedList definitely seems suitable. I can add, get and remove.
Cheers for reading guys!
You are along the right lines. The java.util.Collections package will contain most of what you need.
I would actually use an ArrayList rather than a LinkedList as it is faster for random access and sorting.
However note that it says you should be able to find people efficiently and look them up by name.
That suggests using something like a TreeMap structure, mapping name to a class containing information on each person. Store the names as "Surname, Forename" and they will be sorted correctly.
That will only allow lookups based on the complete and correct name though. If you want to search for partial names the map is less useful.
Related
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'm doing my first Mobile App and i have been studying java for about 2 weeks now so i'm pretty new.
The app that i'm trying to make is a grocery list app.
Basically, I want to sort my grocery list by department wise. For example:
Fruit items will go in a fruitArray
the meat items will go in meatArray
etc.
Should I create a single file for each department (Fruit, meat, bakery) or can i store all my array in the same file and access them separately?
I did some search but i cannot find a topic that answers my question.
I would like to know what would be the best way to do it and if it's to put the arrays in the same file, how can i do that ?
Thanksâș
When you're doing or learning something new, do whatever works for you. Consider trying to do both, as it's experience you'll gain for future.
Some general things to take note of though :
Storing all items in one file could potentially create one massive file (regardless of the project you're working on, im generalizing now)
Storing items in different files increases the overhead of having to handle and manage different files.
These are things you will have to consider and things you'll learn from experience, based on the project and various different aspects.
For the sake of this question, I think storing different items in different files would potentially be a better, simpler solution for now, but it really depends on the entire project and how you plan to implement it. Hope this at least somewhat answers your question. Happy coding and happy learning
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 4 years ago.
Improve this question
I need a hint on an Interview question that I came across. I tried to find a solution but I need advice from experts over here. What are the different strategies you would employ had you came across this particular situation? The question and my thoughts are as follows:
Q. You want to store a huge number of objects in a list in java. The number of objects is very huge and gradually increasing, but you have very limited memory available. How would you do that?
A. I answered by saying that, once the number of elements in the list
get over a certain threshold, I would dump them to a file. I would typically then build cache-like data-structure that would hold the most-frequently or recently added elements. I gave an analogy of page swapping employed by the OS.
Q. But this would involve disk access and it would be slower and affect the execution.
I did not know the solution for this and could not think properly during the interview. I tried to answer as:
A. In this case, I would think of horizontally scaling the system or
adding more RAM.
Immediately after I answered this, my telephonic interview ended. I felt that the interviewer was not happy with the answer. But then, what should have been the answer.
Moreover, I am not curious only about the answer, I would like to learn about different ways with which this can be handled.
Maybe I am not sure but It indicates that somewhat Flyweight Pattern. This is the same pattern which is been used in String pool and its efficient implementation is must Apart from that, we need focus on database related tasks in order to persist the data if the threshold limit is surpassed. Another technique is to serialize it but as you said, the interviewer was not satisfied and wanted some other explanation.
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
Currently my program is filled with many ugly references that often make field or method access look like this: weakReference1.get().weakReference2.get().field1.getSomeCustomObject().field2. I want to move to shorter and faster strong references like field1.field2. But my program design is such that I will also have to go for an ArrayList element-by-element search (in a for-loop) instead of accessing a WeakHashMap by get() method.
Thus, I'd like to understand, can moving to simpler references compensate for rejecting HashMap performance wise. Herewith I presume that WeakHashMap.get() is much faster than a loop-search of ArrayList.
Can someone, please, give me a rough estimate? Or maybe there's even an appropriate comparison table like this one. I'd appreciate that.
Thank you.
Currently my program is filled with many ugly references that often make field or method access look like this:
weakReference1.get().weakReference2.get().field1.getSomeCustomObject().field2
Given that the objects involved are not Data Transfer Objects
this is a violation of the law of Demeter aka Don't talk to Strangers / Tell, don't ask!
Following this LoD principle you should move the operations working with the data in field2 to a new method in the class SomeCustomObject.
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
In Data Structures and Algorithms in Java, the advantages of ordered arrays are stated. One of the advantages, I wish I had some kind of real example for. This is not for homework, but just self-clarification. What are some real cases for when insertion/deletion is not frequent, but searches are frequent? Anything would help even if you can point me in the direction of some github repository. Thank you.
An example would be a dictionary. After it is built, it can be looked up millions of time. Like your paper dictionary, the words in it better be sorted.
While I like leeyuiwah's answer, a more common domain which you can see in commercial context is a data base of some entity, for example the customers or employees, for which normally you create a view. That's why we index them (make the retrieval faster). Indeed, after inserting some records most of the operations will be retrieval which includes a search (based on complicated conditions or a simple identifier).
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
Trying to come up with the simplest way to create binary tree, so i read alot of code online from different sources.
how is it theres so many different ways to create a working binary tree? This is what i dont understand about programming syntax/language... the logic i get.. but i believe there should be a set , uniform foundation to create the same things in the simplest way. Am I wrong?
create tree
create node
create node root
Ok,
I will try to answer your question.
Let's take a big box. You want to put inside some things. Few days after, you will have to find something and use it. Someday, maybe you will want to throw something away.
So, what is your approach, if you are sure, that you will never use any object of them? Probably you will not care where and how you put this object. It is fast and easy to do.
What, if someday, you will want to use some objects? You keep this way and you will be loosing a lot of time for searching or maybe you will try to keep some order inside and easily find an object?
Exactly the same story is with the Binary Trees.
Each of alghoritms has some properties f.e. a lot of algos keep your tree balanced. Before you choose an implementation for your code, think about how you will use it and take a proper one.