Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Java by (3.4k points)

Is there a convention for naming enumerations in Java?

My preference is that an enum is a type. So, for instance, you have an enum

Fruit{Apple,Orange,Banana,Pear, ... }

NetworkConnectionType{LAN,Data_3g,Data_4g, ... }

I am opposed to naming it:

FruitEnum

NetworkConnectionTypeEnum

I understand it is easy to pick off which files are enums, but then you would also have:

NetworkConnectionClass

FruitClass

Also, is there a good document describing the same for constants, where to declare them, etc.?

1 Answer

0 votes
by (46k points)


Enums are classes and should comprehend the rules for classes. Models of an enum are constants and should catch the rules for constants. So


enum Fruit {APPLE, ORANGE, BANANA, PEAR};


There is no purpose for addressing FruitEnum any further than FruitClass. You are just spending four (or five) parts that add
no data.
Java itself supports this method and it is used in their samples.

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...