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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:31:10+00:00 2026-05-17T17:31:10+00:00

I recently ran across a class that had the following field declared: private final

  • 0

I recently ran across a class that had the following field declared:

private final int period = 1000;

In this particular case, the author had intended for it to also be static and since the value couldn’t be altered at any point, there was no real functional reason not to declare it static, but it got me wondering how Java treats final vs. final static primitives.

In particular:

1) How are final static primitives stored? Are they simply compiled directly into the expressions in which they’re used?

2) If they are actually allocated storage, does each instance of the containing class then have to maintain a reference to that location? (in which case, for primitives of less than 4 bytes, each instance of the class would actually be larger than if it simply included the primitive directly as it would in the non-static case)

3) Are compilers now smart enough to determine that in cases such as the one above, the variable is ‘effectively static’ since it would be impossible to have different instances contain different values and therefore optimize it similarly to a final static one?

  • 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-17T17:31:10+00:00Added an answer on May 17, 2026 at 5:31 pm

    1) How are final static primitives stored? Are they simply compiled directly into the expressions in which they’re used?

    Not compiled directly into the expressions. They are compiled into the .class file and referenced by the opcode ldc.

    2) If they are actually allocated storage, does each instance of the containing class then have to maintain a reference to that location? (in which case, for primitives of less than 4 bytes, each instance of the class would actually be larger than if it simply included the primitive directly as it would in the non-static case)

    No, the “reference” is baked into the bytecode, so nothing needs to be stored on a per-instance basis.

    3) Are compilers now smart enough to determine that in cases such as the one above, the variable is ‘effectively static’ since it would be impossible to have different instances contain different values and therefore optimize it similarly to a final static one?

    Not sure, but I doubt it’s optimized at the compiler level. The JIT would probably come into play. However, I’m not at all sure what sort of “performance differences” you are expecting. No matter what the case, the performance impact will be negligible. (static/non-static/final/non-final)

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

Sidebar

Related Questions

I recently ran across this problem while trying to implement a service that has
I recently ran across a website that had some interesting styling on a select
I recently ran across a routine that looks something like this: procedure TMyForm.DoSomething(list: TList<TMyObject>;
I recently ran across some 3rd party C# code which does the following: public
I ran across this case of UnboundLocalError recently, which seems strange: import pprint def
I'm trying to fix a design flaw that I recently ran across in some
I recently ran across this great article by Chad Parry entitled DIY-DI or Do-It-Yourself
I recently ran into a problem that I thought boost::lambda or boost::phoenix could help
I recently ran into a problem with a COM object that was using a
I'm writing a C parser using PLY, and recently ran into a problem. This

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.