Java Programing laungage

Core Java Tutorial

Introduction of Core Java

How To Install JDk and Set of Path

Syntax of java Program

Difference between Java and C/C++

Advantage and Disadvantage of Java

What is Java

Why Java is not Pure Object Oriented Language

Java has Following Features/Characteristics

Limitation of Java Language and Java Internet

Common Misconception about Java

Simple Program of Java

Integrated Development Environment in java

Compile and Run Java Program

Applet and Comments in Java

Tokens in Java

Keywords in Java

Identifier and Variables in Java

Literals/Constants

Data Type in Java

Assignments and Initialization in Java

Operators in Java

Rule of Precedence in Java

Operator on Integer and Separators in Java Programming

Java Control Flow of Statements

If and If-else Selection Statement

Nested If-else and If-else-If Selection Statement

switch case and conditional operator Selection Statement

for and while Loop

do..while and for each Loop

break and labeled break statement

continue and labeled continue statement

return Statement and exit() Method

Escape Sequence for Special Characters and Unicode Code

Constants and Block or Scope

Statement in Java

Conversions between Numeric Types in Java

Import Statement in Java

User Input in Java using Scanner Class

User Input in Java using Console Class

Array in Java

One Dimensional Array

Two Dimensional Array

Two Dimensional Array Program

Command Line Argument in Java

String args Types in Java

Uneven/Jagged array in java

Math Class Function and Constant

Math Class all Function used in a program

Enumerated Types in Java

Object Oriented Programming v/s Procedural Programming

Object Oriented Programming Concepts in Java

Introduction to Class,Object and Method in Java

Class Declaration in Java

Class & Objects in java

Encapsulation in Java

Modifiers/Visibility for a Class or Interrface or member of a Class

Polymorphism in Java

Runtime polymorphism (dynamic binding or method overriding)

adplus-dvertising
Enumerated Types in Java
Previous Home Next

Enum is a keyword which enum type is a special data type used to define collections of constants. A Java enum type is a special kind of Java class. An enum can contain constants, methods etc. Java enum were added in Java 5. For example Number of days in Week. Enum constants are implicitly static and final and you can not change there value once created. Notice curly braces around enum constants because Enum are type like class and interface in Java. similar naming convention for enum like class and interface (first letter in Caps) and since Enum constants are implicitly static final we have used all caps to specify them like Constants in Java. The names of an enum type's fields are in uppercase letters.

In the Java programming language, you define an enum type by using the enum keyword.

Syntax :

public enum Day 
{
	SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
	THURSDAY, FRIDAY, SATURDAY 
}

The enum keyword which is used in place of class or interface.

Example :

public class EnumTest
{
	public enum Day 
	{
		SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
		THURSDAY, FRIDAY, SATURDAY 
	}
	
	Day day;

	public EnumTest(Day day) 
	{ 
		this.day = day;
	}

	public void tellItLikeItIs()
	{
		switch (day)
		{
			case MONDAY:System.out.println("Mondays are bad.");
						break;

			case FRIDAY:System.out.println("Fridays are better.");
						break;

			case SATURDAY:System.out.println("Weekends are best.");
						break;
		
			 case SUNDAY:System.out.println("Weekends are best.");
						break;

			default:System.out.println("Midweek days are so-so.");
					break;
		}
	}

	public static void main(String[] args)
	{
		EnumTest firstDay = new EnumTest(Day.MONDAY);
		firstDay.tellItLikeItIs();
		EnumTest thirdDay = new EnumTest(Day.WEDNESDAY);
		thirdDay.tellItLikeItIs();
		EnumTest fifthDay = new EnumTest(Day.FRIDAY);
		fifthDay.tellItLikeItIs();
		EnumTest sixthDay = new EnumTest(Day.SATURDAY);
		sixthDay.tellItLikeItIs();
		EnumTest seventhDay = new EnumTest(Day.SUNDAY);
		seventhDay.tellItLikeItIs();
	}
}

output :

Mondays are bad.
Midweek days are so-so.
Fridays are better.
Weekends are best.
Weekends are best.

The enum declaration defines a class (called an enum type). The enum class body can include methods and other fields.

All enums implicitly extend java.lang.Enum. Because a class can only extend one parent.

Previous Home Next