Confusion about call-by -value and call - by reference

class A{
public boolean check(String source, ArrayList arr){
//pROCESS ON ARRAYLIST
class B {
A con = new A();
String source="this is string ";
ArrayList arr = new ArrayList();
// suppose Arraylist has some elements
boolean  error= false;
error = A.check(source,arr);
}Is it call by value or call by ref .
Please help
}

Object references are also passed by value. ???Yes, as demonstrated byclass Foo {
    public int bar = 0;
    public static void main(String[] args) {
            Foo foo = new Foo();
            foo.bar = 1;
            System.out.println(foo.bar);
            baz(foo);
            // if this was pass by reference the following line would print 3
            // but it doesn't, it prints 2
            System.out.println(foo.bar);
    private static void baz(Foo foo) {
        foo.bar = 2;
        foo = new Foo();
        foo.bar = 3;
}

Similar Messages

  • Java is call by value or call by reference

    Hi! friends,
    I want to know,java is call by value and call by reference.
    Please give the the exact explanation with some example code.

    All parameters to methods are passed "by value." In other words, values of parameter variables in a method are copies of the values the invoker specified as arguments. If you pass a double to a method, its parameter is a copy of whatever value was being passed as an argument, and the method can change its parameter's value without affecting values in the code that invoked the method. For example:
    class PassByValue {
        public static void main(String[] args) {
            double one = 1.0;
            System.out.println("before: one = " + one);
            halveIt(one);
            System.out.println("after: one = " + one);
        public static void halveIt(double arg) {
            arg /= 2.0;     // divide arg by two
            System.out.println("halved: arg = " + arg);
    }The following output illustrates that the value of arg inside halveIt is divided by two without affecting the value of the variable one in main:before: one = 1.0
    halved: arg = 0.5
    after: one = 1.0You should note that when the parameter is an object reference, the object reference -- not the object itself -- is what is passed "by value." Thus, you can change which object a parameter refers to inside the method without affecting the reference that was passed. But if you change any fields of the object or invoke methods that change the object's state, the object is changed for every part of the program that holds a reference to it. Here is an example to show the distinction:
    class PassRef {
        public static void main(String[] args) {
            Body sirius = new Body("Sirius", null);
            System.out.println("before: " + sirius);
            commonName(sirius);
            System.out.println("after:  " + sirius);
        public static void commonName(Body bodyRef) {
            bodyRef.name = "Dog Star";
            bodyRef = null;
    }This program produces the following output: before: 0 (Sirius)
    after:  0 (Dog Star)Notice that the contents of the object have been modified with a name change, while the variable sirius still refers to the Body object even though the method commonName changed the value of its bodyRef parameter variable to null. This requires some explanation.
    The following diagram shows the state of the variables just after main invokes commonName:
    main()            |              |
        sirius------->| idNum: 0     |
                      | name --------+------>"Sirius"       
    commonName()----->| orbits: null |
        bodyRef       |______________|At this point, the two variables sirius (in main) and bodyRef (in commonName) both refer to the same underlying object. When commonName changes the field bodyRef.name, the name is changed in the underlying object that the two variables share. When commonName changes the value of bodyRef to null, only the value of the bodyRef variable is changed; the value of sirius remains unchanged because the parameter bodyRef is a pass-by-value copy of sirius. Inside the method commonName, all you are changing is the value in the parameter variable bodyRef, just as all you changed in halveIt was the value in the parameter variable arg. If changing bodyRef affected the value of sirius in main, the "after" line would say "null". However, the variable bodyRef in commonName and the variable sirius in main both refer to the same underlying object, so the change made inside commonName is visible through the reference sirius.
    Some people will say incorrectly that objects are passed "by reference." In programming language design, the term pass by reference properly means that when an argument is passed to a function, the invoked function gets a reference to the original value, not a copy of its value. If the function modifies its parameter, the value in the calling code will be changed because the argument and parameter use the same slot in memory. If the Java programming language actually had pass-by-reference parameters, there would be a way to declare halveIt so that the preceding code would modify the value of one, or so that commonName could change the variable sirius to null. This is not possible. The Java programming language does not pass objects by reference; it passes object references by value. Because two copies of the same reference refer to the same actual object, changes made through one reference variable are visible through the other. There is exactly one parameter passing mode -- pass by value -- and that helps keep things simple.
    -- Arnold, K., Gosling J., Holmes D. (2006). The Java� Programming Language Fourth Edition. Boston: Addison-Wesley.

  • Passing values and calling other classes?

    Hello all.
    I have 2 classes(separate .java files). One is a login class and the other is the actual program. Login class(eventually exe file) should open the other class and pass the login parameters if you know what I mean. Is this possible, or do the 2 classes need to be part of one file?
    Thanks alot
    Milan D

    Login class can be another class in another file
    wht u have to do is to make an instance of login class in the class u want to use that class
    like login lg = new Login();
    and call method of login class
    lg.setUser(username);
    where setUser(String user); is a method of login class
    this way u can pass the parameters to login class
    i hope this might be helpful
    regards
    Moazzam

  • Confusion about how object interact and are aware of each other

    I have this java applet
    Two of the classes it contains are the main class with the init method and a UI class that is code for the interface.
    the main class instantiates the UI class anonymously (i think you call it that) i.e it does not put it into a named reference it just creates it by calling new without assigning it to anything.
    When I click on a button from the UI class I want to call a method in the main class...but how so?
    At first I tried to make the function i want to call in the main class static so I could easily call it from the UI class...but then it began to get complex...so i just sent a reference of the main class to the UI class via its constructer.
    Now i want the main class to update a JTable in the UI class, but how? It does not have any reference to the UI class.
    What is really the standard method of operation for this sort of thing when objects have to be calling methods of each other. How do I make them aware of each other.

    the best way to do it is like this:
    public class Main {
      //this is the main class
      private static class MyUIFrame extends JFrame {
        //create the class. It is useable within Main this way
        //static means it doesn't implicitly 'know' about the Main class. You can also
        //remove this and call Main.this to use Main's methods
    }Edited by: tjacobs01 on Apr 11, 2009 2:28 AM

  • Confused about licensing with JDev and components

    Ok, now I'm very confused.
    JDev is free and ADF Faces go to OS but I dont understand what can I deploy and what I cant.
    Could some one explain what can I deploy for free and what not,
    Regards.

    If you are talking specifically about ADF Faces - the version that Oracle provides is part of the overall ADF framework which is free for deployment on the Oracle Application Server and costs money on other servers.
    You can pick up the distribution that Apache will provide from the ADF Faces components that we contributed to them - and then you can use those components for Free on any server.
    Oracle ADF (the drag and drop data binding and the TopLink or ADF BC components) is again free on Oracle AS, and costs money to deploy on other servers.
    And JDeveloper itself is free.

  • Some confusion about 3D TV's and Syncing Glasses

    There has been some confusion about our ad from last week and the offer to sync the 3D glasses with your TV. 
    We by no means intend to confuse our customers or offer fraudulent services.  The offer is new to our stores, and our own employees have been in training just this week.  Let me clarify the services included with the Samsung 3D TV offer that appears in this weekend’s insert. Geek Squad will:
    Set up and connect your TV + up to 5 components.
    Add internet connectable components to your existing wireless network.
    Make sure your 3D glasses work.
    Review and teach you how to use all of your new gear.
    We have some customers who aren’t quite sure how the 3D glasses work, or that the glasses automatically sync with their new 3D TVs.  So this informs them that they can depend on Geek Squad to answer their questions during installation and set-up. There is no additional charge for this – and the Geek Squad 3D installation and networking services are included in the total price of this offer.  
    Matthew
    Community Builder
    Best Buy Corporate

    Can you give details of how you get to £45 per month?
    Phone rental and BB Opt 2 ought not to be more that £32
    You can opt for line rental saver NOW and that will seriously reduce your bill.
    You can also recontract your BB at anytime and unless you recontracted last May or only got BB last May then you are out BB contract and and can cancel or move or negotiate a deal.
    If you are really hard up you could cancel Sky as one senior to another.
    Life | 1967 Plus Radio | 1000 Classical Hits | Kafka's World
    Someone Solved Your Question?
    Please let other members know by clicking on ’Mark as Accepted Solution’
    Helpful Post?
    If a post has been helpful, say thanks by clicking the ratings star.

  • Passing values and calling PL/SQL process via a column link

    Hello all
    I have a report and a link on one of the columns which takes you to another page and passes data from the report to that page. That all works fine. In addition to picking up the details from the report I'd also like the link to call a page process before it goes to the next page using some of the values picked up from the report. This I can get to work by changing the link to a URL and putting in some javascript ie javascript:doSubmit('TEST_PROCESS'); By doing this I "lose" the ability to pass the info from the report via the link.
    Can anyone give me a clue as to how I can achieve both please? I'm assuming I'll need to create my own javascript function but I don't know how to pick up information from a row in a report to pass on.
    Regards
    Helen

    Lets say your link would pass 2 items P1_ITEM and P1_ITEM2 to your process. Just write a quick javascript function to do this and put it in the header:
    <script type="text/javascript">
    function doSomething(pValue1,pValue2){
      $s('P1_ITEM',pValue1);
      $s('P1_ITEM2',pValue2);
      doSubmit('TEST_PROCESS');
    </script>This will set 2 hidden items equal to whatever you pass in. Then you can use these in your after-submit process. To call this from your url, just make the url:
    javascript:doSomething(#COL1#,#COL2#);#COL1# and 2 being your report columns. This should do what you need i think

  • How to pass a value and call SE38 program using SUBMIT statement

    Hello Friends
    I am trying to write a batch program in SE38, that calls other SE38 Programs.
    I don't want to use Parameter command to see the value on screen.
    All I want is to send a range of date (ToDate & FromDate) and generate different reports satisfying this date range condition.
    Can some one please help me with this. I would really appreciate it.
    I have tried the command SUBMIT with options of filling the input fields of the subsequent programs but I don't want to do this.
    I want all the sub programs to be called one after another and the reports generated using the date varialbles I send from the main program.
    I don't want to use se37 functions because of the client's request.
    Any help will be highly appreciated.
    Tks
    Ram

    Yes I am using SUBMIT command but I was not using the right options with the SUBMIT command and once I used the right options, it worked.
    Tks
    Ram

  • 3 year old iPhone 4 has a crackling sound when calls are made and caller can't be heard

    My iPhone 4 has been giving me problems via the earpiece it seems. When I make calls, it starts crackling until I hit the earpiece area till the sound is gone. But when its clear, I can hear the person over the phone but the person can't hear me. I have to hit it a few more times on the earpiece to actually get them to hear me. My mic works fine as sending voice messages are no problems. Anyone else going through this problem and had a solution to this (besides buying a new iPhone - Still waiting for iPhone 5s to be in stock) Hoping for some help on this. Thank you.

    I had major issues with the iPhone 4s battery, however it’s resolved.
    The tech who set the phone up at the Apple store did so with little training.
    if you have a mobile me account. First go and move all your data to the cloud by going on your computer and logging in at me.com/move. The cloud has replaced mobile me, so there is no need for those two accounts
    Also make sure that for any of your email accounts you set them up to fetch, not push. My tech person set them all to have the email servers push data to the phone. The new iphone4s antenna is extremely strong so it will continually try to access stuff that is pushed–***** a lot of battery life doing this. It makes it worse if you have exchange 2010 accounts. Something about changes made to exchange really suck battery life from devices that access such accounts.
    turning of locator and the push notifications from facebook--they have a lot!

  • Confused about Sony HDR-SR7 and iMovie '08 import

    I have my camera set to record at HD XP (15Mb/s). If I look on the camera hard drive at an arbitrary .mts file that is 107.3MB and import that into iMovie '08 at the Full (1920x1080) setting, that 107.3MB file turns into a whopping 854.5MB, while the Large (960x540) setting yields a much more reasonable 287.3MB file size (yet still double the size of the raw file sitting on the hard drive).
    There's got to be some re-encoding going on, but what's the point? Why take a 100MB file and explode it to 800MB when you can't get any more quality out of the 100MB file?
    Is it just the fact that iMovie doesn't actually support whatever native codec Sony's AVCHD uses, so it needs to re-encode it using AIC whose compression isn't as good as whatever codec AVCHD is using?
    So this poses a real dilemma for me - do I import at Full or do I import at Large? Where does one notice the difference? If I blow up the 960 file to display the same size as the 1920 file, I can totally see artifacts on my 30" ACD, but would they show up on my Pioneer plasma TV? PDP-5070HD (1365x768))
    Assuming I stay on Full quality - is there any way I can accurately tell how much hard drive space an import is going to consume? Right now my 60GB drive is rammed to the gills and I want to dump it all, but I need to make sure I have the space. 1:8?

    Hi
    *First: it sounds like you are not importing to iMovie, it sounds like you are trying to browse to the clips. That may not work.*
    Ok - I was trying to import and also to view directly on the camcorder (but not at the same time). It was maybe 2 questions rolled into one so apologies if that was confusing...
    *Second:You have SD and HD mixed, All of the SD has to be imported before any HD can be imported according to the manual.*
    So what would I do, import SD movies first, and then delete it to then import HD specifically? Or do I just import SD and then import HD separately without deleting SD footage from the camcorder?
    *Third point: The clips can be on the hard drive or the card. The camera has to be set to the media with the clips you want to import. If you recorded to the card, then switched to the hard drive, you won't be able to import the card video until you switch back.*
    I dont have a card at the moment - only using the HDD.
    *When you have the import working it is a matter of using the check box to select the clips you want.*
    i assume iMovie loads them all up and asks you which ones you want to import?
    *Alos one final point for video on the card I find it much easier to use a card reader to import. When I plug in the card reader to my usb port it mounts on the desk top, I start iMovie and the import screen comes up after iMovie is all opened up and running.*
    I dont see much point in the card reader at the moment as the HDD is 120GB whereas I assume memory sticks only go to 8GB or so max...
    *I hope I have been of some help.*
    yes thanks for that - but am still confused by the whoel iMovie & HD import situation and how I should be doing it
    All help appreciated

  • E6 belle call screeen problem and call log proble...

    When making / receiving a call, I can only see part of the name (10 characters), if it is longer. Ideally, to see not only the name / surname as a whole, but also to other fields if they are (eg a company), for business is essential. Picture when I disconnected the call but did not help.   Another problem: The Call Log contains only the last 20 , even if the settings of a month's worth.

    Hi,
    That's already by default. If the name of the contact is exceeding 16 characters, it will be cut off on the screen once you call/receive a call from the said contact. Also, the device can only show the name of the contact when receiving/making a call. Including its other information (eg company) is beyond the support of your device.
    With regard to the Call logs, that is unusual. try to perform a soft reset by dialing *#7780#. It should fix the problem.
    Hope this will help you.
    Thanks,

  • Question about project plan value and  availability control

    dear expert:
    I had built a project, and with CJ30, Allocated budget is 10000, in one of  WBS element.
    I created  a network and internal activities,
    when I  assiged a material component (Res + PR) and system can be saved even if the total plan cost value is crossing the budget value.(There is no PR created, now. )
    But, Budget checking is showing error message that budget is exceeded when I created any external service activity and crossing the budget value.(There is also no PR created, now. )
    My question is: what is the difference of the two plan value? Why one is relevant to the budget,and the other is not?
    Note:1) the tolerance limit with ++ (all activity groups), usage say 100% & action 3 (error) to the budget profile. The budget prifile is considered with only overall budget.
    2)In tables COSP, "value types" are all 01 (plan), but VRGNG field values ​​are different, components plan is: KPPE
    Service activities are: KPPP
    3)in CJ30 u2013 Extras>> Availability Control>> Analysis. I could see the following in red colour, these values system not considering into account.
    Entries in this color make no contribution to the assigned value!
    V: Value type not relevant ( Act./Plan/Stat.Act./Stat.Plan/Commt)
    D: Delivery
    S: Settlement to object with no budget control
    R: Revenue cost element
    C: Cost element is exempt cost element
    M: Minimum from actual + commitment and plan per order value update
    P: Plan value is not on apportioned order / network
    B: Plan Costing Single Position
    S: Funds Commitment in Balance
    Following is for material
    COSP 2011 01 8001110100     0000000200 KPPE D RMB             200,000.00  RMB   B
    Following is for service
    COSP 2011 01 8001110400  KPPP D RMB                                10.00  RMB
    regard
    mao jian

    Hi,
    Its not per item category. If  N or L sytem will check the budget if in your system if proper GL's are maintained in OBYC settings BSX and GBB > VBR nad cost elelemtns are created for them. for this you have to cosult with your MM / CO consultant.
    PS is highly inteergratd with CO and all values are updated per cost elements. If values are not updated in cost elements then budget chek wil not happen.
    In you case for material values may be updated in cost elements due to improper OBYC setting so budget check was not done.
    Chekc your OBYC setting and try to create material PR system will check for the budget.
    Check and confirm.
    regards,

  • Confused about pixel aspect ratio and video size

    Hello,
    I have edited a whole dvd full of video and exported it as MPEG-2  NTSC DV Wide - it says 720 x 480, 29.97 fps. I have brought these into Encore and am trying to make a menu but can't seem to get the menu size right. Since I chose the wide format when making the video, which aspect ratio should I use in Encore? It gives me a choice in the properties menu, but when I go to Project settings it says Codec: MPEG-2 Dimensions 720 x 480. Whenever I bring in a menu background from photoshop, it doesn't fit, and is further complicated by the pixel aspect ratio thing. I have no idea what my background size should be to make it fit properly - the templates seem to all be the 4:3 size. What size should I be using in Photoshop and which pixel aspect ratio?
    Is my video codec going to cause me a problem in Encore? I assumed that most tvs nowadays are widescreen (at least not square), so I should do the video wide as well.
    Thanks for any help! I am thoroughly confused.

    Use a template menu from Encore's library. Then modify as you need. That way you know that it will be the right pixel size and par. You cannot made an incorrectly sized/par'd menu work by setting it to 16:9 or 4:3 in the menu properties. It must be correct, and if so, Encore will usually pick the correct setting.
    The Encore project settings for DVD really have no choices: it has to be  720x480 for NTSC. There is no project setting for par. You have to create the menu correctly - just let Encore do that for you by using a template.
    Was your video source widescreen? If so, then you'll be fine on your video. If not, you may need to sort that out also.

  • Please help. I need to register a new itouch for my daughter but confused about apple id's and getting all her stuff transferred to the new itouch from the old one. Plus I want her to have her own apple Id

    My daughter has an old itouch, she uses my apple I'd. I just got her a new I touch, and want to register it, but give her her own apple Id. I just backed up or synced her old itouch to the computer and now I am setting up her new one. If I give her a new apple Id will she then loose all her apps and songs from her old itouch? Please help!! I thought it was supposed to say something like restore from back up or something like that? Maybe that is a next step after I give her her own apple id?

    https://register.apple.com/cgi-bin/WebObjects/GlobaliReg.woa [register an Apple Product]
    https://appleid.apple.com/cgi-bin/WebObjects/MyAppleId.woa/wa/createAppleIdForIK B?localang=en_US&path=%2F%2Findex.jspa [create new apple id]
    You must be logged in to register an Apple Product
    Message was edited by: michael08081

  • Confused about Cinema 30" MacPro and Radeon x1900 help?

    Hey guys, I'm just about to get the 30" monitor for my Macpro which is about 2 years old. I have the ATI radeon x1900xt card installed. I need help
    1) Will this card work with the monitor in its fullest resolution?
    2) Does the monitor come with that dual link dvi cable, or do I need to spend more money on something else to get the best resolution etc.??
    Thanks
    Mo

    On that video card, both of the DVI outputs are dual-link, meaning it can support two 30" displays at full res, so no problem there.
    As far as a dual-link DVI cable is concerned, every 30" monitor that I am familiar with ships with one, so you shouldn't need to buy a separate one. Whatever cable comes with the monitor will give the best resolution.

Maybe you are looking for