SlideShare a Scribd company logo
1 of 7
EnumIt is available from JDK 1.5.
What is enum ?
“An Enum is a special or derived (Non-Primitive) Java type
used to define collections of constants.”
 In simple terms an enum is a list of named constants
that define a new type which has a fixed set of values.
 It is a special class type
 An ref variable of an enumeration type can hold only
the values that are defined by the list.
How to use?
In the Java programming language, you define an enum type by
using the enum keyword.
For example,
you would specify-
dayOfWeek: SUNDAY, MONDAY, TUESDAY, …
month: JAN, FEB, MAR, APR, …
gender: MALE, FEMALE
compassDirections: NORTH, SOUTH, EAST, WEST
Because they are constants, the names of an enum
type's fields are in uppercase letters.
The variable must be equal to one of the values that
have been predefined for it.
enum Season {
WINTER, SPRING, SUMMER, FALL
}
class EnumExample1{
public static void main(String[] args
) {
Season s=Season . WINTER;
System.out.println(s);
}
}
When to use?
You should use enum types any time to represent a fixed
set of constants.
Note:
• Java implements enumerations as class type.
• We don't instantiate an enum using new , it acts much like a class,
i.e. you can give it constructors, add instance variable and methods
and even implement interfaces
Example of specifying initial value to the enum constants
 class EnumExample{
 enum Season{
 SUNDAY(7), MONDAY(1), FRIDAY(5), SATURDAY(6);
 private int value;
 private Season( int value){
 this.value=value;
 }
 }
 public static void main(String args[]){
 for (Season s : Season.values())
 System.out.println(s+" "+s.value);
 }
 }
Key Point’s -
1.enum can't inherit another class(all enumerations
automatically inherit java.lang.Enum class)
2.enum cannot be a superclass,i.e. enumeration
can't be extended

More Related Content

More from Qspiders - Software Testing Training Institute

More from Qspiders - Software Testing Training Institute (20)

QSpiders - Chapter 7 Debugging
QSpiders - Chapter 7 DebuggingQSpiders - Chapter 7 Debugging
QSpiders - Chapter 7 Debugging
 
QSpiders - Chapter 4 Checkpoints
QSpiders - Chapter 4 CheckpointsQSpiders - Chapter 4 Checkpoints
QSpiders - Chapter 4 Checkpoints
 
QSpiders - Simple Recording and Configuration of recording options for HP Loa...
QSpiders - Simple Recording and Configuration of recording options for HP Loa...QSpiders - Simple Recording and Configuration of recording options for HP Loa...
QSpiders - Simple Recording and Configuration of recording options for HP Loa...
 
QSpiders - Wonderlic Sample Question
QSpiders - Wonderlic Sample QuestionQSpiders - Wonderlic Sample Question
QSpiders - Wonderlic Sample Question
 
QSpiders - Chapter- 3 Synchronization point
QSpiders - Chapter- 3 Synchronization pointQSpiders - Chapter- 3 Synchronization point
QSpiders - Chapter- 3 Synchronization point
 
QSpiders - Presentation JMeter
QSpiders - Presentation JMeterQSpiders - Presentation JMeter
QSpiders - Presentation JMeter
 
QSpiders - Memory (JVM architecture)
QSpiders - Memory (JVM architecture)QSpiders - Memory (JVM architecture)
QSpiders - Memory (JVM architecture)
 
QSpiders - Jdk Jvm Jre and Jit
QSpiders - Jdk Jvm Jre and JitQSpiders - Jdk Jvm Jre and Jit
QSpiders - Jdk Jvm Jre and Jit
 
QSpiders - Simple replay and run time settings Loadrunner
QSpiders - Simple replay and run time settings LoadrunnerQSpiders - Simple replay and run time settings Loadrunner
QSpiders - Simple replay and run time settings Loadrunner
 
QSpiders - Major difference
QSpiders - Major differenceQSpiders - Major difference
QSpiders - Major difference
 
QSpiders - Introduction to HP Load Runner
QSpiders - Introduction to HP Load RunnerQSpiders - Introduction to HP Load Runner
QSpiders - Introduction to HP Load Runner
 
QSpiders - Interacting with My SQL Database
QSpiders - Interacting with My SQL DatabaseQSpiders - Interacting with My SQL Database
QSpiders - Interacting with My SQL Database
 
QSpiders - Automation using Selenium
QSpiders - Automation using SeleniumQSpiders - Automation using Selenium
QSpiders - Automation using Selenium
 
QSpiders - Server Architecture
QSpiders - Server ArchitectureQSpiders - Server Architecture
QSpiders - Server Architecture
 
QSpiders - Installation and Brief Dose of Load Runner
QSpiders - Installation and Brief Dose of Load RunnerQSpiders - Installation and Brief Dose of Load Runner
QSpiders - Installation and Brief Dose of Load Runner
 
QSpiders - Good to Know Network Concepts
QSpiders - Good to Know Network ConceptsQSpiders - Good to Know Network Concepts
QSpiders - Good to Know Network Concepts
 
QSpiders - Cloud computing(cloud server)
QSpiders - Cloud computing(cloud server)QSpiders - Cloud computing(cloud server)
QSpiders - Cloud computing(cloud server)
 
QSpiders - Basic intel architecture
QSpiders - Basic intel architectureQSpiders - Basic intel architecture
QSpiders - Basic intel architecture
 
QSpiders - Introduction to JMeter
QSpiders - Introduction to JMeterQSpiders - Introduction to JMeter
QSpiders - Introduction to JMeter
 
QSpiders - Introduction to Performance Testing
QSpiders - Introduction to Performance TestingQSpiders - Introduction to Performance Testing
QSpiders - Introduction to Performance Testing
 

Recently uploaded

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 

Recently uploaded (20)

VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 

QSpiders - Enum Java Topic

  • 1. EnumIt is available from JDK 1.5.
  • 2. What is enum ? “An Enum is a special or derived (Non-Primitive) Java type used to define collections of constants.”  In simple terms an enum is a list of named constants that define a new type which has a fixed set of values.  It is a special class type  An ref variable of an enumeration type can hold only the values that are defined by the list.
  • 3. How to use? In the Java programming language, you define an enum type by using the enum keyword. For example, you would specify- dayOfWeek: SUNDAY, MONDAY, TUESDAY, … month: JAN, FEB, MAR, APR, … gender: MALE, FEMALE compassDirections: NORTH, SOUTH, EAST, WEST
  • 4. Because they are constants, the names of an enum type's fields are in uppercase letters. The variable must be equal to one of the values that have been predefined for it. enum Season { WINTER, SPRING, SUMMER, FALL } class EnumExample1{ public static void main(String[] args ) { Season s=Season . WINTER; System.out.println(s); } }
  • 5. When to use? You should use enum types any time to represent a fixed set of constants. Note: • Java implements enumerations as class type. • We don't instantiate an enum using new , it acts much like a class, i.e. you can give it constructors, add instance variable and methods and even implement interfaces
  • 6. Example of specifying initial value to the enum constants  class EnumExample{  enum Season{  SUNDAY(7), MONDAY(1), FRIDAY(5), SATURDAY(6);  private int value;  private Season( int value){  this.value=value;  }  }  public static void main(String args[]){  for (Season s : Season.values())  System.out.println(s+" "+s.value);  }  }
  • 7. Key Point’s - 1.enum can't inherit another class(all enumerations automatically inherit java.lang.Enum class) 2.enum cannot be a superclass,i.e. enumeration can't be extended