Core Java - Interview Questions and Answers for 'Enumeration' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Core Java - Interview Questions and Answers for 'Enumeration' - 5 question(s) found - Order By Rating

 Q1. What is the difference between Enumeration and Iterator ?Core Java
Ans. Enumeration can iterate only legacy collections like Vector , HashTable and Stack whereas Iterator can iterate both legacy and non legacy collections.

Enumeration is less safer than Iterator

Enumeration is fail safe whereas Iterator is fail fast

Iterator allows for removal of element while traversal whereas Enumeration doesn't have remove method.

Enumerations were introduced in Java 1 whereas Iterators were introduced with Java 2

Enumerations have methods like hasMoreElements and nextElement whereas Iterators have methods like hasNext, next and remove

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     enumeration vs iterator  collections      Basic        frequent


 Q2. What is an enumeration?Core Java
Ans. An enumeration is an interface containing methods for accessing the underlying data structure from which the enumeration is obtained. It allows sequential access to all the elements stored in the collection.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   enum   enumeration interface   basic interview question

Try 2 Question(s) Test


 Q3. Can we override compareTo method for Enumerations ?Core Java
Ans. No. compareTo method is declared final for the Enumerations and hence cannot be overriden. This has been intentionally done so that one cannot temper with the sorting order on the Enumeration which is the order in which Enum constants are declared.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   compareto   final methods   enum   enumeration      expert


 Q4. Shall we keep the enumeration name in all capital letters as it contains all constants ?
Ans. Enum is actually a class with pre defined constants. So enum name should follow the convention of the Class name. Though the constant names or the Enum variables should follow the convention of having all capital letters.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   enum   enumerations   java conventions   java naming conventions


 Q5. In Hibernate, While defining Criteria, Have you ever faced any problem while adding restrictions with user defined types or Enums ?Hibernate
Ans. Yes, with Enum as was getting an exception while doing equality check for enum field.

got it fixed by adding @Enumerated(EnumType.STRING) to the field in entity.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate   hibernate criteria   enumerations



Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: