Proper java naming convention for enums

jcardy@uoguelph.ca's picture

Does anybody know the proper java naming convention for enums?

I generally don't use enums very often but I can't remember what the proper naming convention would be.

For instance:

public static enum COLOUR { RED, BLUE, ORANGE }

or should it be treated like an object and be named Colour?

Does java have any recommendations?

I always capitalize the enumerated values.

As you can see, this isn't exactly a life or death question here. Just for my own interest.

jgaber@uoguelph.ca's picture

The short answer is, there

The short answer is, there are no naming standards. The longer answer is, since there's no naming standards for Java, You typically use the same standards that are used in C.
___________
Josh Gaber

jcardy@uoguelph.ca's picture

Wow there really aren't any

Wow there really aren't any real naming conventions for java. There is, but I'm pretty sure that there only loose recommendations. According to java, they don't like my "_" prefix for instance variables, oh well.

ansi c says enums should be like the following:

enum Fruit { Apples, Oranges, Kumquats };

Makes sense to me.

Very first result on Google

"enums properly are classes, so should start with a capital letter. However, it is also considered ok to use all lower case, e.g. enum Fruits { Peach, pear }."

Quoted from the first result on my Google Query:
http://mindprod.com/jgloss/codingconventions.html

And there certainly are conventions for Java. Remember the textbook from OOP? It has a lot of them in there.

Randall Roberts
SOCIS President

jgaber@uoguelph.ca's picture

I meant naming standards for

I meant naming standards for enums. -_-
___________
Josh Gaber

Re: Gaber

Naming Standard, Coding Convention. What's the difference?

Coding Convention for enums is to treat it as a class, so you capitalize it. What do you mean by naming standard?

Randall Roberts
SOCIS President

jcardy@uoguelph.ca's picture

Yeah, I'm mistaken. There

Yeah, I'm mistaken. There are plenty of coding conventions for java. Sun even publishes them.

I'm going to go with capitalizing like a class (seeing how it is essentially a class), and all capital enumerates (whether or not enumerates is a word is another issue).

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.