aspose file tools*
The moose likes Beginning Java and the fly likes Variables declared in upper case Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Variables declared in upper case" Watch "Variables declared in upper case" New topic
Author

Variables declared in upper case

Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218
I have just come across the following:

static final int ASCENDING = 2;
static final int DESCENDING = 4;

This raised the following question: Why are the variables ASCENDING and DESCENDING in upper case?

I thought variables were lower case and a Class began with a capital letter.

Thanking you in advance.
Werner van Mook
Greenhorn

Joined: Feb 21, 2005
Posts: 7
If you define so called constants (final and meybe static) the code conventions tell you to write them in capitals only.
If multiple words then seperate them with _

Regards
Werner
Mehul Sanghvi
Ranch Hand

Joined: Feb 04, 2002
Posts: 134
Hi,

It is just a naming convention in Java to name all "final static" (constant) variables defined as part of class defination in ALL CAPS.

Regards,
Mehul.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
This is just a widely used convention for constants. Notice the final static modifiers.

Other examples are Math.E, Math.PI, Color.RED, Color.BLACK (the Color class also defines lowercase versions Color.red for example).


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218
Many thanks for your quick response.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Variables declared in upper case