This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Variables declared in upper case" Watch "Variables declared in upper case" New topic

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

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 _

Mehul Sanghvi
Ranch Hand

Joined: Feb 04, 2002
Posts: 134

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

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 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
It's not a secret anymore!