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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:50:24+00:00 2026-06-14T23:50:24+00:00

my java class private static final String constantString = Constant; private static final Integer

  • 0

my java class

private static final String constantString = "Constant";    
private static final Integer constantInteger = 5;
public static void main(String[] args) {
    String s2 = constantString + "append"; // LINENUMBER 9
    Integer i2 = constantInteger + 7; // LINENUMBER 10
}

Byte code

 LINENUMBER 9 L0
    LDC "Constantappend"
    ASTORE 1
   L1
    LINENUMBER 10 L1
    GETSTATIC TestClass.constantInteger : Ljava/lang/Integer;
    INVOKEVIRTUAL java/lang/Integer.intValue()I
    BIPUSH 7
    IADD

Question No1 : Why compiler not replacing final Integer (constantInteger) value with 5,but for String it did!

if remove final keyword for Integer variable

java code :

private static Integer constantInteger = 5;

byte code :

LINENUMBER 10 L1
GETSTATIC TestClass.constantInteger : Ljava/lang/Integer;
INVOKEVIRTUAL java/lang/Integer.intValue()I
BIPUSH 7

the byte code is same in two different cases (static final Integer , static Integer)

Question No 2 : Then What is the use of making Integer final ?

  • 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-14T23:50:26+00:00Added an answer on June 14, 2026 at 11:50 pm

    The compiler does not bother to notice that a final Integer with a non-null value is, necessarily, non-null. So it goes ahead and unboxes it. It is entirely possible that the JIT compiler will improve this on the way to machine code; it seems pretty unlikely either way that this is a real problem for the performance of your application.

    ‘final’ is about semantics, not performance. The language guarantees the semantics; the performance is entirely at the whim of implementors. So, to answer ‘question #2’ explicitly: the point of final is to have the semantics of preventing modification. Also note the rules for embedded anonymous classes, where they may only use final local variables.

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

Sidebar

Related Questions

I have the following (Java) code: public class TestBlah { private static final String
Please consider the following java source: package com.stackoverflow; public class CondSpeed { private static
what the below code line does in java. private static final String PERMISSIONS_KEY =
public class SaveData extends Activity implements OnClickListener { private DataManipulator dh; static final int
Why does this code crash? CustomDatabaseHelper.java: public class CustomDatabaseHelper { SQLiteDatabase db; private static
I have the following controller @Controller @RequestMapping(/project/view.html) public class ProjectViewController { private static final
how to initialize a private static member of a class in java. trying the
If I have a java class which is package-private (declared with class, not public
I'm trying to change a private static final field with Java Reflection. But it
call.java: public class Call extends Activity{ boolean timerhasstarted; Intent callIntent; public void onCreate(Bundle savedInstanceState)

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.