Difference between initialising variables inside a loop and outside it.

What is the difference between initialising a variable, say a String, inside a loop and outside it?
Are there performance differences, memory allocation issues etc? Or is there no difference at all?
For example:
1. Outside the loop
String s = "";
while (foo)
s = some variable;
2. Inside the loop
while(foo)
String s = some variable;

.Hence, it definitely improves the performance of your code.That only depends on the code. Modern VM like Hotspot are very good at optimizing things.
for the in the loop thing.
Its true you need to create a new Object but memory doesnt need to be reallocated always because the VM knows the previiously declared Object has become available (it went out of scope)
Generaly: dont use the outside loop because you think it might help performance: always leave micro-optimizations for the VM.
It might be faster but its not a certantiy

Similar Messages

  • What is difference between local variable and property node ?

    What is difference between local variable and property node ?
    " 一天到晚游泳的鱼"
    [email protected]
    我的个人网站:LabVIEW——北方客栈 http://www.labview365.com
    欢迎加入《LabVIEW编程思想》组——http://decibel.ni.com/content/groups/thinking-in-labview

    To make things clear, here are two small examples that show how nasty locals and value properties can be to the naive programmer.
    - Open the diagram of the race condition.vi before running it and try to predict what will be the values of the two counters after the third run.
    - Use the Compare Locals Properties and Wires.vi to find out how slow locals and value properties can be (times 1000+).
    This being demonstrated, I must add that I use globals and value properties quite often, because they are often very convenient
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Race condition.vi ‏9 KB
    Compare Locals Properties and Wires.vi ‏18 KB

  • What is the difference between Instance variable and Global variable?

    Hi folks,
    Could you please explain me, "what is the difference between Instance variable and Global variable?"
    Are they really same or not?
    --Subbu                                                                                                                                                                                                                                                                                                               

    Hi flounder,
    I too know that there is no such a term GLOBAL in java.
    generally people use to say a variable which is accessible throught out the class or file has global access
    and that will be called as a global variable...
    my point is very much similar to what Looce said.
    In simple that is not a technical term, but just a causual term.
    In technically my question is, "What is the difference between a instance variable and public variable?".
    Hi looce,
    Thanks for the reply. even thats what my understanding too....in order to confirm that i raised this question..
    Your reply has given a clear answer...... thanks again.
    --Subbu                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • What Is The Difference Between Save As Self-Contained Movie and Exporting

    What Is The Difference Between Save As Self-Contained Movie and Exporting a Video as a Quicktime File

    Save As places the file inside a .mov container. No re-encoding.
    Your still have the option to save this file as "self-contained" (all the parts travel with the file) or "reference" (small file sized movie that merely "points" to the movie parts).
    A reference movie can't play if the source files can't be found. If they are moved or deleted the reference movie will fail and it can't be re-created.
    Exporting is done to convert one QuickTime format to another. Typically you do this with a high quality source file. Exporting previously compressed files is a bad idea that leads to unpredictable results.
    QuickTime doesn't open WMP formats without third party software help (Flip4Mac is one). You can't convert (export) WMP formats without paying extra fees to upgrade their software.

  • What is the difference between BO Designer connect BW QUERY and BW CUBEuFF1F

    HI  friend,
        What is the difference between BO Designer connect BW QUERY and BW CUBE?
    which one is better?
    Best regards.
    Howard

    Hi Howard,
      You can use autorization variables in  SAP BW and maitain the security there, using that you can apply diferent security not only at Infoobject levet you can apply security per BEX Query.
      Here is some informaion about BEX and SAP BusinessObjects
    BI metadata feature _______SAP OLAP BAPI support level
    Characteristics (incl. Time and Unit)_______ InfoCube/BEx Query
    Hierarchies_______ InfoCube/BEx Query
    Basic Key Figures_______ InfoCube/BEx Query
    Navigational Attributes_______ BEx Query only
    Display Attributes_______ InfoCube/BEx Query
    Calculated Key Figures / Formulas_______ BEx Query only
    Restricted Key Figures_______ BEx Query only
    Custom Structures_______ BEx Query only
    Variables_______ BEx Query only
    I hope this help you.
    BEst regards,
      Fede

  • Difference between using app server connection pooling and using the driver

    Hi all,
    How to get connection pooling with out application server and tomcat also?
    What is the difference between using app server connection pooling and using the driver supported connection pooling?
    Regards,
    Murali

    maybe the performance of App server pool is better than the JDBC pool,
    for you don't know wether the implementation of the JDBC interface is good or bad.

  • What the difference between u0093Valuate GL Account Open Itemsu0094 and u0093Valuate G/

    hi gurus
    What the difference between “Valuate GL Account Open Items” and “Valuate G/L Account Balances”?
    We found out that when we perform valuate GL account Open items there will be reversal done at the same time whereas when we perform Valuate G/L Account Balances there is NO reversal posting even though we hv entered the reversal posting date and Period.
    Pls advise which one we should perform?

    “Valuate GL Account Open Items” are for open item managed accounts including vendor/customer accounts. The valuation is performed for each (open) line items on key date specified.
    "“Valuate GL Balance" is for account NOT managed on Open Item basis but managed in foreign currency. The period balance of key date in foreign currency is valuated. Reversal document can be created by selecting 'Reverse postings' in "Postings" tab.
    Kyoko

  • Difference between the design of clusters PCLx and others like RFBLG etc .

    There are a few nagging questions which I was not able to find in the forum hence i have to post a new question.
    I am a little confused about the difference between the different clusters .
    If i start with RFBLG i.e. the cluster for BSEG BSEC etc ,I can see that the tables which are part of this cluster
    can be viewed through different methods like
    1) whr usd list for RFBLG
    2) dd02l table and give the required parameters there
    now when I compare this with another so-called cluster PCL1 if find that PCL1 is not recognized as  a cluster
    and also I am not able to see the same in dd02l table when i give PCL1 and the tabtype as cluster which I was able to see
    for the RFBLG ,there are other tables similar to RFBLG .
    1) SO what is the difference between the RFBLG type of clusters and the PCLx type of cluster
    2) are pclx and rfblg..type of clusters same ?
    3) why does PCL1 shows that it is a transparent table ? where as rfblg shows in a diff way in se11
    4) i know we access data from PCL1 using import and export stmts ,DO OR CAN WE DO THE SAME FOR RFBLG
    5) I found that each and evry cluster table had diff fields ,this was kinda surprising for me as I had been thinking
    that all cluster tables need to follow a certain rule ,SO WHO DECIDES THE FIELDS OF A TABLE CLUSTER ?
    6) PCL1 has the index button enabled ,which again I think is not according to the cluster table rules?how?
    7) I understand that we can save data in form of internal tables in the PCL1 cluster ,can we do the same in RFBLG ?
    8) Can I think on lines that PCL1 and RFBLG type of cluster are two totally different types of data dictionary objects
    and the usage and implementation of both of them is different and that the design and the BASE of both of such objects
    is different .
    I know this is a long list but I am sure that answers to these questions would really require some one who has really really work hard and invested a lot of time in understanding the dictionary system.I am awaiting a few answers ,few hints and a healthy discussion till we get them .
    Thanks ...
    a

    Hello,
    1/
    BSEG is a typical Cluster Table.
    This means that the physical table BSEG does NOT exist in the database, physical data for BSEG is stored in the database (table) cluster RFBLG.
    In ABAP however you can perform selects on BSEG (with all fields from the SAP repository structure, see SE11 on BSEG), during execution the SAP database layer will translate these statements to physical selects in the RFBLG database table, so in ABAP this is transparant.
    More info :
    [http://help.sap.com/saphelp_nw04/helpdata/en/cf/21f083446011d189700000e8322d00/content.htm|http://help.sap.com/saphelp_nw04/helpdata/en/cf/21f083446011d189700000e8322d00/content.htm]
    2/
    PCL1, PCL2, ... are normal SAP transparent tables, however in HR they are often called HR cluster table.
    Transparent tables are SAP objects where there is also a database table with the same name that contains the physical data.
    However the PCL tables are somewhat different from normal transparent tables (data is compressed, external programs can not interpret the data, ...).
    This means that in ABAP you can not use simple SQL statements to access data in PCL tables (because of compressed format).
    In stead statements like EXPORT TO DATABASE and IMPORT FROM DATABASE need to be used.
    More info :
    [http://fuller.mit.edu/hr/cluster_tables.html|http://fuller.mit.edu/hr/cluster_tables.html]
    Wim

  • Is there any difference between R/3 4.7 version and ECC 5.0????

    Hi All,
      Is there any difference between R/3 4.7 version and ECC 5.0 for the transaction RSA5.
    Regards,
    Andy

    Andy
    Functionality wise I didn't see any difference other than new datasources in ECC5.0
    Thnaks
    Sat

  • What is the difference between credit memo in invoice year and in next year

    Hi!
    I'm new here.I'm study SAP ERP.I don't know what is the difference between credit memo in invoice year and credit memo in next year (asset accounting).Can you show and give me an example, please!
    Thanks and best regards!
    Edited by: dinhtuan on Jun 28, 2010 3:10 PM

    Hi,
    Maybe have a look at the SAP Help for further information (http://help.sap.com) : e.g. 'Posting Credit Memos Integrated with Vendor'  or 'Posting a Credit Memo Offset Against a Clearing Account' 
    Transaction type 105 for credit memo on current acquisition made in the current year, posting key 75. Or transaction type 160 for credit memo on acquisitions from prior years. posting key 75.
    Note: determine if the asset was acquired in the current fiscal year or in a closed fiscal year (Display asset values).
    If the asset was acquired in a fiscal year that is now closed, correct the past depreciation using a write-up (in that case check out and refer to Posting Write-Ups).
    I hope this helps.
    Kind regards,
    Brigitte

  • What is the difference between these two reports MC.1 and MB5L

    Hi
    what is the difference between these two reports MC.1 and MB5L?
    what is the Purpose of each report?
    Material ledger is activated for this plant, we found some amount difference between these two reports, my client accounting department used to compare these two reports while year end/month end closing
    Thanks
    Raju

    MC.1 will give you the report for plant analysis as per plant .
    MB5L report will give you list of stock value as per G/L account wise.

  • Difference Between SAP ECC. 6.0 and 4.6c

    Hi
    What is the Difference Between SAP ECC. 6.0 and 4.6c
    with respect to module wise, like SD, MM, FI,
    thanks
    Satish

    Hi,
    There is lot difference between 4.6c and 6.0
    1) ecc 6.0 coming with inbuild webdynpro , BSP it is not 4.6c
    2) In ecc we have interactive forms concept where it was not there in 4.6c
    3) 4.6c there is no unicode concept here we have unicode and non unicode
    You can follow the link also
    difference between SAP 4.6C and SAP ECC6.0
    Rgds,
    Suman

  • Difference between Oracle9i 9.2.0.3 and Oracle9i 9.2.0.4 JDBC Drivers

    Hi everybody,
    Can you tell me what is Difference between Oracle9i 9.2.0.3 and Oracle9i 9.2.0.4 JDBC Drivers briefly?
    In my application I am using Oracle9i 9.2.0.3 JDBC Drivers. But it is not supported when I retrieved Data with junk character from CLOB.because of IO Exception it showing Bigger type length than Maximum
    if i used Oracle9i 9.2.0.4 JDBC Drivers it is working properly.
    I am using WAS 4.0.3 , JDK1.3 and Oracle 9.0.
    Shall I use Oracle9i 9.2.0.4 in my application and I want to know it will create any new problem in my application or not ?
    please Reply me ASAP.
    i am waiting for your reply
    thanks a lot
    bye
    Message was edited by:
    paulusazapakcom

    Can you tell me what is Difference between Oracle9i
    9.2.0.3 and Oracle9i 9.2.0.4 JDBC Drivers briefly?Search the Oracle site. That should tell if there are any differences at all. I would assume that there would be some bug fixes.
    please Reply me ASAP.
    i am waiting for your replySuch lines are better avoided.

  • Differences between the "Adobe Acrobat Versions 7 and 9"

    Dear Adobe Support Team,
    I need to know the differences between the "Adobe Acrobat Versions 7 and 9". I have worked with Acrobat 7 and have used the same script after installing Acrobat 9 for Automation Testing with QTP for validating pdf. The object "AcroExch.AVDoc" is not getting identified as object while working in QTP in the system/machine which has Acrobat 9 installed, whereas it works well in the machine which has Acrobat 7 installed . So it will be better if two things are known as per my understanding, ie.,
    it must have compatibility issue (i need the difference between "Adobe Acrobat versions 7 & 9" to assure this) or
    installation issue( which can be confirmed if the former question is answered).
    So i kindly request you to help me out for this scenario.
    Kind Regards,
    Vikraman.G

    Countless new features were introduced between Acrobat 7 and 9, are you really expecting us to type out a full list from memory?
    If you are having specific issues with the Acrobat SDK, first refer to the Acrobat SDK for the higher version. If there remains an issue I suggest posting about the specific problem in the Acrobat SDK forum, rather than asking for an encylopedia of all possible information...
    Note that Adobe do not support multiple installations of Acrobat on the same machine, so you can expect development issues if you do this.

  • Difference between execution mode of Print preview and Print for Output

    Hello,
    Can anybody tell the difference between execution mode of print preview and print for an output (For eg. PO output or Invoice)?. I am trying to download some documents linked to Purchase order to desktop. The code is written in the same driver program for printing PO and it is executed after smartform function module is called. It works fine in print preview mode and it fails in print mode. The reason why download fails in print mode is that GUI not available (just found from debugging).
    Any ideas?
    Thanks
    Anil

    HI
    try using any other printer and find out if you are getting the correct output. The printer needs to support Multiple Unicode encoding schemes like UTF 8, UTF 16BE, and UTF 16LE, plus special characters and logos, bi-directional text layout, and custom characters..

Maybe you are looking for