Skip to main content

Posts

Showing posts with the label Enumeration

Difference between Enumeration and Iterator

Use Iterator always for better programming. One big difference between Iterator and Enumeration is (apart from what Pallav has already mentioned), iterator is fail-safe. If you are using an iterator to go through a collection you can be sure of no concurrent modifications in the underlying collection which may happen in multi-threaded environments. Well, apart from being an advantage this also is said to decrease performance by a tad. However, that's negligible. (Some amount of processing is involved in checking for modifications). If you see the docs it says about "well defined semantics" for the iterator, the fail-safe property adds to that. Enumeration and Iterator are interfaces in java.util package. Enumeration is the old Interface(for legacy classes like Hashtable). Iterator is for the new classes like HashSet,HashMap.. Enumeration and Iterator are used to just count the no of elements and view it. But Iterator has an additional method for deleting elements...

Java Collections Interview Questions -Latest

For any java professional Collections Framework is important subject to be expert in it. Since these concepts are used all most all business logics. Wherver the Java interview happens, interviewer expects you should be 40% of technical skills from Collections framework. So you should be perfect in In this subject. I have collected some of the very important and gunshot questions that have been asked most of the interviews in all major companies. I discussed with many guys who has gone for java interviews and collected these Java Collections Framework Questions & Answers. Just check them out.

What is the difference between an enum type and java.lang.Enum?

-- An enum type, also called enumeration type, is a type whose fields consist of a fixed set of constants. The purpose of using enum type is to enforce type safety. While java.lang.Enum is an abstract class, it is the common base class of all Java language enumeration types. The definition of Enum is: public abstract class Enum> extends Object implements Comparable, Serializable All enum types implicitly extend java.lang.Enum. The enum is a special reference type, it is not a class by itself, but more like a category of classes that extends from the same base class Enum. Any type declared by the key word "enum" is a different class. They easiest way to declare a enum type is like: public enum Season {     SPRING, SUMMER, AUTUM, WINTER }