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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:02:58+00:00 2026-05-15T07:02:58+00:00

In java Program, parameters which is defined as String in method declaration. But in

  • 0

In java Program, parameters which is defined as String in method declaration. But in method definition it is accessed as final String variable. Whether it’ll lead to some issues (like security, memory problem)?

For Example:

Method Declaration

join(String a,String b);

Method definition

public void join(final String a,final String b)
{
    Authenticator au = new Authenticator(){
        public PasswordAuthentication getPasswordAuthentication(){
        return new PasswordAuthentication(a,b)}
    };
}

Please help for me and clarify my doubts. Thanks in advance

P.S. I’m accessing a and b as final variable because I’ve got to use it in the inner class.

  • 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-15T07:02:59+00:00Added an answer on May 15, 2026 at 7:02 am

    final simply means that the reference/primitive variable can not be assigned a new value. It’s not the same as const concept (which Java doesn’t have); it does NOT guarantee immutability. String in Java, of course, is already immutable enough (barring nasty reflection attacks).

    Using final modifier for parameter arguments will have no effect on security or garbage collection. It’s done for readability and to enforce coding convention that parameter variables aren’t being reused in the method to store other values.

    Upon encountering a final modifier, a human reader can be assured that the value of this variable, once assigned, will not change within its scope. The compiler would enforce this behavior, and would not compile a program that illegally tries to assign a new value to variable that is declared final.

    JLS 14.2.4 final Variables

    A variable can be declared final. A final variable may only be assigned to once. It is a compile time error if a final variable is assigned to unless it is definitely unassigned immediately prior to the assignment.

    As mentioned, however, final does not in itself guarantee immutability of the object being referred to. A final StringBuilder sb declaration guarantees that sb, once assigned and within its scope, will not refer to another StringBuilder instance. StringBuilder itself, of course, is a mutable object.


    final and inner classes

    Another use of final modifier is to allow local variables etc to be used by an inner class:

    JLS 8.1.3 Inner Classes and Enclosing Instances

    Any local variable, formal method parameter or exception handler parameter used but not declared in an inner class must be declared final.

    This has to do with how inner classes using these variables are compiled in Java, an implementation detail that perhaps is not all too relevant for the discussion. Essentially, the values of these final variables are given to the inner classes at construction time. Subsequent changes to the local variables (if allowed) would not be seen by the inner class instance. To ensure proper semantics, these local variables must thus be declared final.


    Effects of final modifier for local variables at run-time

    final modifier for local variables/formal method parameters is a compile-time concept, and is not present at, say, the bytecode level (i.e. it plays a very different role than final modifier for fields, classes and methods). Thus, this concept simply doesn’t exist at run-time, where final and non-final local variables are indistinguishable; the usage of the keyword itself would not have any effect on garbage collectibility and/or performance.

    Garbage collectibility is defined in terms of whether or not there are live references to an object. Local variables and method arguments go out of scope at the end of the method (or the block they’re declared in), regardless of whether or not they’re declared final. Going out of scope means the reference is "dead". The object itself may still have live references from elsewhere.

    In this particular case, the formal method parameters are declared final so that they can be used in an inner class. As mentioned above, the inner class would copy these references for its own use. Thus, in this particular case, the Authenticator object would have references to the String objects referred to by a and b.

    Simplistically speaking, the more references to an object there are, the harder it would be to qualify as garbage illegible for collection. The underlying factor, however, is the liveness of these references, not whether or not they’re final.


    On profiling

    It’s good to understand the concepts to clear any doubts on memory usage/performance issues; it’s better to just profile and see if the issues are real, and fix them as necessary. A well-designed system should be highly adaptable to these kinds of changes.

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

Sidebar

Ask A Question

Stats

  • Questions 538k
  • Answers 538k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer self.pageSetupClass = [[PageSetup alloc] set:self.pageID]; What does set: return? Is… May 17, 2026 at 2:03 am
  • Editorial Team
    Editorial Team added an answer You are describing immutability, a feature of functional languages. It's… May 17, 2026 at 2:03 am
  • Editorial Team
    Editorial Team added an answer Some techniques I've seen: Some sort of sound that's played… May 17, 2026 at 2:03 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I started to work in translating a Java program which has tens of dialog
I am creating a GUI using Java. This GUI launches a program from the
I have a Java program where I have a JMenu with an arbitrary number
There is a good function that I need, which is implemented in the Java
I've a bash script that sequentially calls a java program. That's a bit tricky
Lets say we have a program which contains such classes: public interface AbstractItem {
I would like to generate Eclipse Java Project with my Java program. When I
java.lang.annotation.ElementType : A program element type. The constants of this enumerated type provide a
I've a web page on which certain section is being populated by ajax. I
Question: Where do I have to look when I want to know which character

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.