Answer any three (3) of the following questions. These questions cannot be answe
ID: 3602700 • Letter: A
Question
Answer any three (3) of the following questions. These questions cannot be answered in one or two sentences! If you really understand the question you will have at least a healthy paragraph to say on the subject. Use the next page and the backs of pages if you need more room. L. Explain the purpose of specifications. Include discussion of the contract model of tions and the terms requires and ensures (or pre-condition and post-condition). is the purpose of an Iterator? What are the advantages of using an Iterator, over IL. What more traditional techniques? concepts do they represent? What is their benefit to the software designer? of each? III. What are Java Interfaces (as identified by the keyword interface)? What object-oriented N. Compare the array and linked list data structures, what are the advantages/disadvantages V. Explain the design flaws in the JCF versions of Stack and Queue. What specifically did we VI. Explain, in detail, the phrase representation determines algorithm do to resolve these issues?Explanation / Answer
Hi,
This is a very subjective question, not sure how you will be graded but i can try and explain these to you.
Answering any 3 as requested,
2. Iterators are variables that can be used to traverse the underlying container, we use this to provide a way for other to consume and iterate through the underlying list of the classes we define,
Iterator is specially implemented to be thread safe,
Also, iterator is generic and prdouces faster list, for example traditional technique like get(index) works well on array but is very slow on a linkedlist, in this case if we use iterator, it will faster
Also iterators are thread safe i.e if you want to modify thee array while you are iterating it, iterators are of great help as they areare fail-fast: if the list is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.
3. java interfaces are special kind of classes which cannot have which can only contain method signatures and fields. It cannot contain an implementation of the methods, only the signature of the method.
In java they are used to achieve polymorphism, i.e to extend one or more classes in OOP paradigm,
we need to implement an interface in order to use it, we define it like below,
public interface Example{
public String test= "test";|
public void test();
}
Interfaces generally form a middle ground in terms of OOP principles, they are actually a concept of abstraction and encapsulation. Think of them like a contract being established, whicever classes implementing the interface must implement all the method definitions defined in the interface.
For designer, it is more like, I want all my classes of this type "Need to have all such methods..."
4. Arrays and Linked lists
Both have their own pros and cons
Thumbs up if this was helpful, otherwise let me know in comments
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.