Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6533645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:09:11+00:00 2026-05-25T10:09:11+00:00

there is a rule which says: Names representing constants (final variables) must be all

  • 0

there is a rule which says:

Names representing constants (final variables) must be all uppercase
using underscore to separate words
(taken from http://geosoft.no/development/javastyle.html)

that works fine for primitive types like int or strings:

private static final int MAX_COUNT = 10;

But what’s about non primitive types? In most cases I’ve seen the following:

private static final Logger log = Logger.getLogger(MyClass.class);

or in singletons, where instance variable is not in upper case.

The question is what is the right way to declare those types of variables (like log and instance)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:09:11+00:00Added an answer on May 25, 2026 at 10:09 am

    That’s still a constant. See the JLS for more information regarding the naming convention for constants. But in reality, it’s all a matter of preference.


    The names of constants in interface types should be, and final
    variables of class types may conventionally be, a sequence of one or
    more words, acronyms, or abbreviations, all uppercase, with components
    separated by underscore "_" characters. Constant names should be
    descriptive and not unnecessarily abbreviated. Conventionally they may
    be any appropriate part of speech. Examples of names for constants
    include MIN_VALUE, MAX_VALUE, MIN_RADIX, and MAX_RADIX of the
    class Character.

    A group of constants that represent alternative values of a set, or,
    less frequently, masking bits in an integer value, are sometimes
    usefully specified with a common acronym as a name prefix, as in:

    interface ProcessStates {
      int PS_RUNNING = 0;
      int PS_SUSPENDED = 1;
    }
    

    Obscuring involving constant names is rare:

    • Constant names normally have no lowercase letters, so they will not normally obscure names of packages or types, nor will they normally shadow fields, whose names typically contain at least one lowercase letter.
    • Constant names cannot obscure method names, because they are distinguished syntactically.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In commit messages there is a rule which says: Lines starting with '#' will
Is there a good resource which describes the why behind PMD rule sets? PMD's
There is a programming rule that says that a method should instead of asking
There's a rule that says Only mock objects that you own. I think I
There is a Checkstyle rule DesignForExtension . It says: if you have a public/protected
I'm confused about which to use and when. Is there a rule of thumb?
Is there a general rule of thumb to follow when storing web application data
Is there a general rule of thumb as to how many classes, interfaces etc
Is there a good rule of thumb for when nonatomic properties should be used
There is a general rule of OO design that you should model is-a relationships

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.