What is the difference between these to methods?

public void firstMethod(){
     int x = 5;
}and
public int secondMethod(){
     int x = 5;
     return x;
}I just don't see the difference. I guess I am still a little confused on what the return statement does.

The return statement just alows me to use the method as a type of variable, right?The proper explanation is that expressions can evaluate to either l-values or r-values, where an l-value is something to which you can assign an r-value. So in the statement "x = x + 1;", the first x evaluates to an l-value (which you can normally think of as the location of x - doesn't make so much sense when you're thinking in terms of stack machines like the JVM), and the second x evaluates to an r-value (the value currently stored in x), as does the expression "x + 1". If you have a method returning type T, you can substitute a call to that method anywhere you have an expression which evaluates to an r-value of type T.
From a practical point of view, you don't need return statements, but by not using them you constrain yourself to either having very large methods or using lots of global variables.

Similar Messages

  • What is the difference between these setter methods

    What is the difference between these two setter methods??
    <jsp:useBean id="checking" scope="session" class="bank.Checking" />
    <jsp:setProperty name="checking" property="balance" value="0.0" /> and
    <jsp:useBean id="checking" scope="session" class="bank.Checking" >
    <jsp:setProperty name="checking" property="balance" value="0.0" />
    </jsp:useBean>

    Homework question?
    The answer is on this page (Step 5)
    http://java.sun.com/products/jsp/syntax/1.2/syntaxref1217.html#8865

  • What is the difference between organisation payment method and Assignment payment method?

    What is the difference between organisation payment method and Assignment payment method?
    As i am a new bie, i am curious to know this though it might sound a silly question.
    Thank you,
    Kuton

    You can create an Organization payment method of any Payment type(Cash, Check, BACS, NACHA etc) under the same country.
    All these will be valid payment methods on the payroll description form.
    And you can even attach these to a person.
    In which case you will have a Base currency (say USD) and payment currency (say GBP).
    These cases are not normal and only used by people who use a single BG for paying employees in 3-4 countries.
    So, unless you need to pay in different currencies, do not use it.
    Cheers,
    Vignesh

  • 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.

  • What is the difference between these two sticks of RAM?

    I am upgrading my Macbook 2.2 GHz Intel Core 2 duo from 2GB of ram to 4GB
    What is the difference between these two kits?
    4GB Kit (2 x 2GB) 200 Pin DDR2-667 PC2-5300 256x64 CL5 1.8V SODIMM ($102.00)
    4GB Kit (2 x 2GB) eRam 200 Pin DDR2-667 PC2-5300 CL5 1.8V SODIMM ($88.00)

    Probably nothing of any consequence. Some places can just negotiate better deals with suppliers. Or one of a million other factors that can affect price is in play here.
    When buying RAM, I generally find it's better to pay a little extra to get a brand that's known for quality. I usually stick to Crucial myself. If you look around, you can probably find some real steals out there, but I don't know... With stories of people who literally go dumpster diving, salvaging stuff that was slated for disposal, then turning around and selling it... I prefer not to take chances. If you are, by all means, go for the cheaper one.

  • What is the difference between these two portalapps folders on the Server?

    Hello,
    On the Server there are two portalapps folder:
    1. Under: C:\usr\sap\JXX\JC00\j2ee\cluster\server0\apps\sap.com\irj\servlet_jsp\irj\root\portalapps
    2. Under: C:\usr\sap\JXX\JC00\j2ee\cluster\server0\apps\sap.com\irj\servlet_jsp\irj\root\WEB-INF\portal\portalapps
    Can someone please explain me what is the difference between these two portalapps folders and under which case will I turn to which folder?

    Hi Roy,
    The one at this location
    Under: C:\usr\sap\JXX\JC00\j2ee\cluster\server0\apps\sap.com\irj\servlet_jsp\irj\root\portalapps
    has all the files from the WEB-INF folder i.e. these are the non-web resources and cannot be accessed via HTTP(S) examples would be imgaes, CSS etc that you want only your application to access
    those under
    Under: C:\usr\sap\JXX\JC00\j2ee\cluster\server0\apps\sap.com\irj\servlet_jsp\irj\root\WEB-INF\portal\portalapps
    they have all the .JAR files, portalapp.xml, config properties etc. these are web resources and can be accessed via HTTP(S)
    Hope this is of help.
    Akhilesh

  • What is the difference between these two commands?

    What is the difference between these two commands?
    DROP TABLESPACE users INCLUDING CONTENTS;
    DROP TABLESPACE users INCLUDING CONTENTS AND DATAFILES;
    --------No.202

    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_9004.htm#i2133717

  • What is the difference between these two cards

    What is the difference between the?X-Fi Fatalty and the X-Fi XtremeGamer Fatalty Professional Series. I want to replace my X-Fi Platinum with one of these cards.

    does any know the difference?

  • What is the difference between function and method

    Hey I need help I dont know which is the difference between function and method ?
    Does anybody can ask me this question.
    Thanks

    jverd wrote:
    The first two answers were also correct.Also the blocked message, quoted here for posterity:
    "Tinkerbell" wrote:
    Methods are defined by Java whereas functions are not. ~

  • What's the difference between these two backup systems?

    When I bought my Macbook Pro I bought a Seagate external HD that used Bounceback Express as its backup application. But now my Mac defaults to Time Machine. What's the difference between the two applications? When I use Time Machine to back up my hard drive to the Seagate external, is it doing the same thing as Bounceback Express used to?

    In analog terms, to explain YCbCr use the example of the COMPONENT output from your DVD player. It use 3 separate cables (Y = Luminance = Green Cable), (Y-B = Blue Color Diff = BLUE Cable) and (Y-R = Red Color Diff = RED Cable). In the analog world, RGB is actually RGBHV (5-wire) and is adaptable to 15-pin VGA with a simple passive adapter. Many people will mistakenly refer to Analog Component video as RGB, since the cables are Red, Green and Blue.
    So, since all that mumbo jumbo means essentially the same, this appears to be the digital "equivalent" of what is known as Component Video in the Analog world... What I said about RGBHV does not apply to the 10-bit color, but thought I'd mention it anyway.
    -BChil

  • What are the difference between these Extractors?

    What are the difference between ReflectionExtractor, ValueExtractor and KeyExtractor?
    Thank you

    Why not use ValueExtrctor in this example?
    cache.addIndex(new ReflectionExtractor("getAge"), true, null);
    cache.addIndex(new ChainedExtractor(reflectAddrHome,
    new ReflectionExtractor("getState")), true, null);Does the folllowing script OK?
    cache.addIndex(new ValueExtractor("getAge"), true, null);
    cache.addIndex(new ChainedExtractor(reflectAddrHome,
    new ValueExtractor("getState")), true, null);Thank you

  • What is the difference between these tow?

    Hi,
    Inside a JFrame's code both
    getContentPane.add (...)and
    add (...)both are working.
    How come they are working identically? What is the difference between them?

    Darryl.Burke wrote:
    And learn to read the API.
    As a conveniance add and its variants, remove and setLayout have been overridden to forward to the contentPane as necessary.
    dbProbably first learn where to find it, here:
    http://java.sun.com/javase/6/docs/api/

  • What is the Difference Between these IF statements

    Hello
    Can someone tell me the difference between these two IF statements.
    -- IF STATEMENT 1--
    IF v_transcode not in ('A','C','D') THEN
    raise_application_error (-20000, 'Error Invalid Transcation Code');
    END IF;
    -- IF STATEMENT 2 --
    IF v_transcode <> 'A' AND v_transcode <> 'C' AND v_transcode <> 'D' THEN          
    raise_application_error (-20000, 'Error Invalid Transcation Code');
    END IF;
    Thanks

    Your if condition wherein you do
    v_transcode <> 'A' and v_transcode <> 'C' and v_transcode <> 'D'.
    I would think this is more better in terms of performance, because if the first clause (v_transcode <> 'A') fails nothing else needs to be evaluated, and it can skip the if condition there itself,
    but in case of
    v_transcode not in ('A', 'C','D'),
    it has to scan through the entire list.
    On the other side, if you have just 2 or 3 values to compare this makes sense, otherwise we may have to use the in operator.
    --Bhargavi                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • What is the difference between these two matrices

    Hi,
    I was given some code from Altenbach to fix a problem I was having, his example works perfectly but when I connect it to my matrix it gets errors, so my question is what is the difference between the random matrix he made and the matrix coming out of the eigenvector node of the eigeinvector eigenvalue vi.?
    Thanks in advance for your help.
    Attachments:
    SortColumnsBySum.vi ‏14 KB

    Thank you,
    I should have seen that this was wat it was outputting. Please excuse my ignorance beacuse I am fairly new at this, so I can see that the sort complex sorts the colum in ascending order vertically what I need to do is rearrange the order of the matrix horizontally column by column with the sum of the column being the order. E.g if the sum along the column verically is the largest then that column is made column 1 etc. Is it possible to do this with either of the functions you mentioned? I think that I will need to keep the values neagative and posative so that I can take the largest value column, is this correct?

  • What is the difference between these two charging cycles??

    Hi,
    When u check out this http://www.apple.com/batteries/
    it says something about 2 hours Fast Charge and 4 hour Trickle Charge!!
    what is the difference between both of them?
    i charged my iPhone that day for 4 hours but i didn't notice any difference and it says Full after 2 hours!!
    does it matter if it is charged through the computer or a power outlet on the wall??
    Thank you

    agent_s87 wrote:
    When u check out this http://www.apple.com/batteries/
    it says something about 2 hours Fast Charge and 4 hour Trickle Charge!!
    what is the difference between both of them?
    In total it takes 4 hours to recharge the battery. You won't really know the difference actually if you plug it in when you go to bed for 7 hours. It actually states 2 hours to fast charge and 2 hours trickle charge. If you look closely at the chart it's based on 4 hours in total.
    i charged my iPhone that day for 4 hours but i didn't notice any difference and it says Full after 2 hours!!
    does it matter if it is charged through the computer or a power outlet on the wall??
    No it doesn't matter each one. You can buy any number of wall chargers and power packs at your local store. Go to Bestbuy.com and type 'iPhone Power' for select power plugin iphones.
    - Griffin - PowerBlock Charger for Apple® iPod® and iPhone
    - Griffin - PowerBlock Universal Dual AC Charger
    - DLO - Power Pack Home and Auto Chargers for Apple® iPod® and iPhone
    - DLO - Power Bug for Apple® iPhone
    - Apple® - USB Power Adapter for Apple® iPod® and iPhone
    - Belkin - Power Central with Cable Catch for Apple® iPod® and iPhone - White
    - Incase - Power Slider Case for Apple® iPhone 3G - Black
    With the last one "Incase - Power Slider Case for Apple® iPhone 3G - Black" gives you a whole day worth of a charge on standby without having to put the phone on Airplane Mode to conserve power. I kept it on in my pocket for 12 hours and the iPhone was still active.
    Message was edited by: JoeZinVA

Maybe you are looking for