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 8892061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:54:00+00:00 2026-06-14T22:54:00+00:00

I have used final and static variables as well. what i found about these

  • 0

I have used final and static variables as well. what i found about these variables is,

final variable

  • A final variable can only be initialized once, either via an initializer or an assignment statement.

  • Unlike the value of a constant, the value of a final variable is not necessarily known at compile time.

what variables should i declare as final-

Most often i use those variables whose value is constant universally and can never changed, such as the value of PI.

public static final double PI = 3.141592653589793;

static variables

  • These are those variables which belongs to the class and not to object(instance).

  • Static variables are initialized only once , at the start of the execution .

  • A single copy to be shared by all instances of the class

  • A static variable can be accessed directly by the class name and doesn’t need any object.

what variables should i declare as final-

Most of the time, i use those variables which i want to initialize only once and use them in the enitre class.

When to use final static variable

Now, i came across a term final static in one of my database project. I found that some of the database objects or even database version were declared as statci final.

 static final String DATA_BASE = "BackUpDatabase.db";
    static final int DATA_BASE_VERSION = 1;

Now, my question is what variables should we declare as final or static or final static, as using either of them could have solved the issue, then wyh to use both together.

  • 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-06-14T22:54:01+00:00Added an answer on June 14, 2026 at 10:54 pm
    static -  Only use when a variable which is used globally 
    final -  Only use when you need to declare a value as constant 
    
    static final - Only use when a value is globally used and it is a constant.
    
    : - Here global means across all the instances of a java class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Where have you mostly used the initialization block? Can you use these to assign
I have another error, unexpected type required:variable found:value and I can't figure out why.
In Java, when should static non final variables be used? For example private static
I've seen answers on here that you can use final static const variables in
I have used auto complete textbox previously. That auto complete works only when i
In my Android programs, I frequently used : private static final boolean D =
I've read quite a bit about initialization of static class variables in c++ and
Possible Duplicate: Why are static variables considered evil? I have the habit of using
Possible Duplicate: Why are only final variables accessible in anonymous class? This is the
I have seen much code where people write public static final String mystring =

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.