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

  • SEARCH
  • Home
  • 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 6029835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:56:46+00:00 2026-05-23T04:56:46+00:00

In near future we might be enforced by a rule by which we can

  • 0

In near future we might be enforced by a rule by which we can not have any hard coded numbers in our java source code. All the hard coded numbers must be declared as final variables.

Even though this sounds great in theory it is really hard/tedious to implement in code, especially legacy code. Should it really be considered “best practice” to declare numbers in following code snippets as final variables?

//creating excel
cellnum = 0;

//Declaring variables. 
Object[] result = new Object[2];

//adding dash to ssn
return ssn.substring(1, 3)+"-"+ssn.substring(3, 5)+"-"+ssn.substring(5, 9);

Above are just some of the examples I could think of, but in these (and others) where would you as a developer say enough is enough?

I wanted to make this question a community wiki but couldn’t see how…?

  • 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-23T04:56:47+00:00Added an answer on May 23, 2026 at 4:56 am

    Definitely no. Literal constants have their places, especially low constants such as 0, 1, 2, …

    I don’t think anyone would think

    double[] pair = new double[PAIR_COUNT];
    

    makes more sense than

    double[] pair = new double[2];
    

    I’d say use final variables if

    • …it increases readability,
    • …the value may change (and is used in multiple places), or
    • …it serves as documentation

    A related side note: As always with coding standards / conventions: very few (if any) rules should be followed strictly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the near future, my organisation will have to change both the machine name
have written a stochastic simulation in Java, which loads data from a few CSV
I have seen HTML 5 coming up in near future. How does it differ
I will be starting a small Java (GWT really) project in the near future
I'm a newbie in the field, but in the near future I have to
In the near future I want / will design an intranet application , which
I will have to be using JavaCompilers in the near future so I am
I have the following problem, in near future I will need to write a
In the near future I have to develop an interface for integration between SAP
I have an OLD server running DG/UX that will in the near future be

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.