Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Variables declared in upper case

 
Maureen Charlton
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Maureen Charlton
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks for your quick response.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic