• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

code conventions and constants variables

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have a dilemma how the name of constant fields should look like.

In the LockManager class I need a field that holds information about currently locked records. I would like to declare it as a Map and call this field �lockedRecords�.

Could you pleas tell me how this field should be declared?

a) private static final Map LOCKED_RECORDS = new HashMap();
b) private static final Map lockedRecords = new HashMap();

On the one hand I found in the "Java code conventions" guide an information saying that "The names of variables declared class constants should be all uppercase." On the other hand calling the method in the following way...

LOCKED_RECORDS.wait();

...looks really strange to me.

Can anyone clear it up for me?

Thanks,
Wojtek
 
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

a) private static final Map LOCKED_RECORDS = new HashMap();
b) private static final Map lockedRecords = new HashMap();



Hi Wojtek,

Definitely a: constants are indeed always in upper case. This may look strange when the constant is an object, which' state can still change, but this is the correct way.

However, you might consider making it non-final and then you should make it like:

private static Map lockedRecords = new HashMap();

That looks less strange.

Frans.
 
I like you because you always keep good, crunchy cereal in your pantry. This tiny ad agrees:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic