Where do you store local final vaiable in? Stack or Heap or else?

Hi all,
I know local variables are stored in the stack, but how about local final variables? Are they stored in the stack too? What are their life times? Do they "die" with the method after the method is finished?
class Example{
void doStuff() {
final String z = "local variable";
Where is z stored? Is it gone when doStruff() is finished?
Thanks a lot

davy_wei wrote:
Thanks DrClap, but it's not the answer to my question.Yes, it was. You asked where final local variables are stored and DrC gave you the correct answer--all local variables, whether final or not, are on the stack. He answered the question you asked.
>
See the complete example,
class Example {
private String x="Outer";
void doStuff() {
String x="local variable";
class InnerClass {
public void exampleMethod() {
System.out.println("x is "+x);
System.out.println("Local variable x is "+x);
MyInner mi=new InnerClass();
mi.doStuff();
otherMethodInTheExample(mi);    // you can pass the reference of mi to other method
}You are not able to compile it because the virable x is local. The InnerClass can not access the local variables in the enclosing method, which is doStuff(). Before even after the method completes, the inner class object mi might still be alive on the heap if the method otherMethodInTheExample() store the reference in an instance variable. That's the reason why InnerClass can not access the local variable x.
However, if we change the local variable x to final, the code can compile and work.The local variable is still stored on the stack. However, since is value is known and known not to change before the inner class gets it, the inner class can get a copy of its value. This would not work if it were non-final.
Now I have the question. Why the InnerClass can access x when it is set to final. Is x store in the heap too?The inner class gets its own copy of the variable. Since its value is final, it's okay to have multiple copies floating around, since it's impossible for them to get out of sync.

Similar Messages

  • Where do you store your videos?

    My 80 GB iPod has more space than my computer does, and after buying several seasons worth of TV shows, I've run out of room on my computer, but still have space on the iPod. Where do you store all of these video files? I don't have a DVD burner (just a player), so I can't burn them onto DVDs.

    Mist people store their video in the cloud.

  • Where do you store documents and passwords on Ipad?

    where do you store documents and passwords on Ipad?

    Usually on the iPad, documents are associated with a particular app, which has its storage area for documents. A good Swiss Army Knife for docs is GoodReader.
    Do a search in the iTunes App Store and you will find scores of password apps.

  • Where do you store your remote?

    OK - I admit - I've had my MBP for less than three days and I've already lost my remote control (it must be around here somewhere - I've just no idea where). When I finally get a bag for my computer (and after I FIND the remote - if I find my remote) I'll just store it in my bag. But for now I have a simple (and tight) sleeve: nowhere to store the remote (unless it will fit in the ExpressCard slot?).
    I'm beginning to think Velcro may do the trick - anyone else had a remote go missing and, if not, where are you keeping it so that it will be handy?

    I found it! I had tossed it in one of the compartments of my old PowerBook case... and I'm leaving it there until my new backpack for my MBP...
    ...as to the usefulness of the remote on a 15" screen, I see it more as a novelty when, for instance, you're sitting at the airport, your favorite hotspot, etc., and someone becomes interested in the photos of your vacation snaps. But I did note, looking at the Dell site at their 1.6" thick Intel Core Duo laptops, that they sell a remote for use with the XP media center OS. And, boy, not only is the computer big and ugly, so is the remote!

  • Where do you store the remit-address on the vendor master

    Where do we store the vendor remit-to address in the vendor master record?  We're on ECC 6.00.

    HI,
    I think you are aware of 3 types of vendor creation which is FK01, MK01 and XK01.
    XK01 is used for purchasing releted as purchasing data is present.
    Use MK01 / FK01 where only company data is present and this vendor created using MK01 / FK01 cannot be used in the PO's, IF we try to do it then the system will show up an error stating that purchasing cannot be done for this vendor.
    Thanks & Regards,
    Kiran

  • Just got my 1st ever iMac, where do you store the remote?

    Hi I just got me 1st ever imac computer.
    I have read there is a place where you can magentically attach it to the imac so it doesnt get lost - whee is it? its an ALU 20" iMac
    if not where do people store there remote? as I know what will happen to mine if its not stuck on!!
    Also how do you change the battery if it goes in the remote?
    cheers
    Andy

    The new Macs dont have a magnet in it like the old iMacs, which is bad. I just put my remote right next to my Mac. To change the battery you sting something to the small button under the remote. Then a battery holder should pop out.

  • Where do you store Hard coding values?

    Hi All,
    We have a requirement to call a 3rd party web service from SAP for which there are 12 - 13 attributes which are constant values and are not going to change. These can be hard coded inside the implementation methods but I do not want to do it. Say after 3 months there is a additional attribute that need to be added then in that case I need not touch the code back.
    We can store it Z tables which is one option. I would like to get ideas from experts here in the forum what would you do in this type of a scenario instead of hard coding?
    Please post in your feedback from the maintenance perspective across landscapes.
    Thanks,
    Nagarajan.

    Hello Nagarajan,
    you can create the constants in the Assistance class or create a separate interface for storing the constant values.
    If there is any change in the constant value, then you have to change the class/interface. this can't be avoided.
    BR, Saravanan

  • Local final variables

    Hi!
    I suppose this topic pops up from time to time in forums (I've found some threads after google-ing some), but I couldn't find any authentic answers to this.
    According to the standard coding guidelines, how on Earth should you write local final variables?
    The java coding guidelines don't explicitly mention this case, only class-level final (static final) variables and some "ANSI" constants. (I don't have any idea what "ANSI constant" is supposed to mean, anyway).
    Thanks!

    public int getSomeValue(final String parameter) {
    final int length = parameter.getLength();
    // do something
    }Would you call "length" a constant here? Obviously
    not, so why do we declare it final? Because it
    doesn't change during the execution of this method
    and to avoid accidentally assigning a different value
    to it.I'm not sure I wouldn't. For several years I've been pretty satisfied with C++'s notion of "const" (in fact, I really miss real "const" functionality in Java, but that's another story).
    You could write the equivalent in C++:
    int getSomeValue(const std::string parameter) {
    const int length = parameter.length();
      // or .size()? I don't remember, but doesn't matter... :)
    }You could even write things like this:
    for(int i=0;i<5;++i) {
    const int j = 2*i;
    std::cout << j << endl;
    }So, C++ says: if a variable is "const", its value won't change after it's created. The way I see it, the const variable is "recreated" every time you step into the block where it's defined from the outside. (I don't know whether it looks like the same from the implementation point of view, but that doesn't matter.)
    And whatever C++ says, it's so, because it is a correct language. :)
    Anyway, what you're saying makes sense, and if there's a more explicit way of saying "this is a constant" -as you suggested-, I'm going to use it.
    But about the naming convention, I see there's a pretty good unison here, so thanks! :)

  • Where does flash stores the local shared object data

    HI All,
    I'm using shared object to store local data:
                    var so:SharedObject = SharedObject.getLocal(storageName);
                    // Store the data
                    so.data.userName = userName;
                    so.flush();
    Where does it actually saved on my hard disk (in windows vista operating system).
    10x,
    Lior

    http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Live Docs_Book_Parts&file=lsos_087_3.html
    The term local refers to the location of the shared object.
    In this case, Adobe Flash Player stores the SharedObject file locally
    in the client's home directory.
    When you create a shared object, Flash Player creates a new
    directory for the application and domain. It also creates an empty
    *.sol file that stores the SharedObject data. The default location of
    this file is a subdirectory of the user's home directory. On Windows,
    this directory is the following by default:
    c:/Documents and Settings/username/user_domain/Application Data/Macromedia/Flash Player/web_domain/path_to_application/ApplicationName/objectName.sol
    If you request an application named MyApp.mxml on the local host, in the Flex context, and within a subdirectory named /sos, Flash Player stores the *.sol file in the following location on Windows:
    c:/Documents and Settings/username/user_domain/Application Data/Macromedia/Flash Player/#localhost/flex/sos/MyApp.mxml.swf/objectName.sol

  • I tried to rent a film on my MacBook but it comes up with, In order to rent, you need to authorise this computer. To authorise this computer, select "Authorise Computer..." from the store menu. Where is the store menu and how do I sort it?

    I tried to rent a film on my MacBook but it comes up with, In order to rent, you need to authorise this computer. To authorise this computer, select "Authorise Computer..." from the store menu.
    Where is the Store menu and how do I authorise my computer?
    Please help.
    Thank you.

    Move the cursor to the very top of the computer's screen, click on Store in the menu bar, and choose Authorize this Computer.
    (115518)

  • I need the font style century gothic for a project im working on, but neither my final cut pro x nor my photoshop have this font style. Where do you get/buy new fonts?

    I need the font style century gothic for a project im working on, but neither my final cut pro x nor my photoshop have this font style. Where do you get/buy new fonts?

    Not on this list.
    Maybe it gets installed with something else? For example, I have MS Ofiice on the 10.7 system but not on the others.
    Russ

  • Where do you guys store your videos?

    Just wondering where mist people store their video, in the movies folder or in iMovie? I currently am importing all the movies taken from my iPhone in the past 2 years to iMovie. A folder named let's say June 2010 has 16 videos in it and so I import that entire folder and create an event called June 2010 and so on. But lately I'm questioning this method cause I can't see a way to see the date of one of those videos once in iMovie, the only thing the event shows me is let's say June 02 through June 27 2010. How do you do it?

    Mist people store their video in the cloud.

  • Where is   sign when you call international number, but first you call local number and after connect open keyboard and see that sign   doesn't exist only 0

    Where is   sign when you call international number, but first you call local number and after connect open keyboard and see that sign   doesn't exist only 0

    No that is not work. Try to call some number and when is connect click on keyboard and you can see that sign "+" doesn't exist.
    So I use local number, when I'm connect I have option to call international number but like "+3193675xxxx" how I can put?
    Before on iOS 6 I do it.

  • Where do you find the serial no. of the logic pro product when it is bought in the app store

    where do you find the serial number of the logic pro 9 product when you download it from the app store.  It is needed to start up the product the first time.

    Well there really isn't any serial number, or at least my copy from the app store doesn't have one. It is tied to your iTunes/app store account. In the app store, look at the help menu....
    Update applications
    App Store keeps track of updates for the applications you purchased. The Updates button in the toolbar shows the total number of application updates available for downloading.
    The number of updates is also displayed on the App Store icon in the Dock.
    Manage application updates
    Click Updates in the toolbar.
    For updates in the list, you can:
    Download and install all of the updates at once, or download and install a specific update.All of the updates listed on the Updates page are free.
    Pause, resume, or cancel a download.

  • Where is LDAP  store in solaris 9?

    I have solaris 9 fully installed in my machine, but I can't find LDAP software in my system.
    can Anyone show me where is LDAP stores in Solaris 9?

    Try the System Administration Guide: Naming and Directory Services (DNS, NIS, and LDAP) ( http://docs.sun.com/doc/806-4077 ). As mentioned in that doc, you'll need to set up Directory Server before you can use it.
    Hope that helps,
    Mark

Maybe you are looking for