Objects - Pass by refrence or pass by value ----Confusion

Hii Javaties
I have confuison regardhing whether objects are passed by value or refernce -----------------------------------------------------
i have a function ( test() ) that calls
another function ( change(Test_Bean) ) which takes a bean as a parameter.
If in this calling function i change the value of the bean , then the value of bean is actually altered in calling function .
function change(Test_Bean)
     test_bean.setName("Peter");
function test()
      Test_Bean test_bean=new Test_Bean();
       test_bean.setName("Tom");
       change(test_bean);
       System.out.println("Name ="+ test_bean.getName());
       /* Name = Peter is printed */
}Can anybody tell me why is this so ?

Your code demonstrates the proper functioning of pass
by value. You altered the state of an object by using
the correct method. That has nothing to do with
attempting to reassign the reference which would be
pass by reference and you can't do.If this is pass be value , then how can i change the value of original copy ?
If i am using the correct method to alter the state , then it sould alter the state of the local copy not the of original object.
I am still confused .......

Similar Messages

  • Java is pass by value or pass by refrence

    Can any one explain whetherjava is pass by value or pass by refrence.

    Everything in Java is passed "by value". Everything.
    Pass-by-value
    - When an argument is passed to a function, the invoked function gets a copy of the original value.
    - The local variable inside the method declaration is not connected to the caller's argument; any changes made to the values of the local variables inside the body of the method will have no effect on the values of the arguments in the method call.
    - If the copied value in the local variable happens to be a reference (or "pointer") to an object, the variable can be used to modify the object to which the reference points.
    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.... 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.
    -- James Gosling, et al., The Java Programming Language, 4th Edition
    [Pass-by-Value Please (Cup Size continued)|http://www.javaranch.com/campfire/StoryPassBy.jsp]

  • Where do we pass tax condation type and condation value in this bapi: SD_SALESDOCUMENT_CHANGE

    Hi Experts,
    I am using this to change sales order. SD_SALESDOCUMENT_CHANGE
    I am passing condation type and condation values for each line item under table parameter CONDATION_IN.  Here in which fields do i need pass tax condation type and condation value.
    please give me suggestion it is really help ful.
    Thanks
    laxmi

    Hi ,
    Pass condition type and condition value in fields COND_TYPE and COND_VALUE under table parameter CONDATION_IN. Also pass 'X' to above fields in table parameter of CONDITIONS_INX.

  • How to pass a variable more than one values?

    How to pass a variable more than one values?

    You can't.
    During 1 session, 1 ODI variable can have only 1 value at a time.
    If you need more than 1 value, you will have to do somethink like a loop inside your package, and refresh the variable value each time.

  • Passing a large number of column values to an Oracle insert procedure

    I am quite new to the ODP space, so can someone please tell me what's the best and most efficient way to pass a large number of column values to an Oracle procedure from my C# program ? Passing a small number of values as parameters seem OK but when there are many, this seems inelegant.

    Passing a small number
    of values as parameters seem OK but when there are
    many, this seems inelegant.Is it possible that your table with a staggering amount of columns or method that collapses without so many inputs is ultimately what is inelegant?
    I once did a database conversion from VAX RMS system with a "table" with 11,000 columns to a normalized schema in an Oracle database. That was inelegant.
    Michael O
    http://blog.crisatunity.com

  • Whats the difference betweeen passing the table variable and table valued parameter?

    Hi Everbody
      Can someone one tell me what's the difference between passing a table variable and table valued parameter to a stored procedure or function? Can both be used to pass a table to a stored procedure/function?
    Regards
    Regards

    They are essentially the same. What we call a table variable is a local
    variable. A table-valued parameter is an incoming parameter to the
    procedure. The only difference is that the parameter is readonly.
    When you call a stored procedure, you can pass a table variable as the
    actual parameter. Or a table-valued parameter that you pass on.
    CREATE PROCEDURE nisse_sp @tvp sometype READONLY AS
    DECLARE @local someothertabletype
    EXEC pelle_sp @tvp, @local
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Confused about passing by reference and passing by valule

    Hi,
    I am confuse about passing by reference and passing by value. I though objects are always passed by reference. But I find out that its true for java.sql.PreparedStatement but not for java.lang.String. How come when both are objects?
    Thanks

    Hi,
    I am confuse about passing by reference and passing
    by value. I though objects are always passed by
    reference. But I find out that its true for
    java.sql.PreparedStatement but not for
    java.lang.String. How come when both are objects?
    ThanksPass by value implies that the actual parameter is copied and that copy is used as the formal parameter (that is, the method is operating on a copy of what was passed in)
    Pass by reference means that the actual parameter is the formal parameter (that is, the method is operating on the thing which is passed in).
    In Java, you never, ever deal with objects - only references to objects. And Java always, always makes a copy of the actual parameter and uses that as the formal parameter, so Java is always, always pass by value using the standard definition of the term. However, since manipulating an object's state via any reference that refers to that object produces the same effect, changes to the object's state via the copied reference are visible to the calling code, which is what leads some folk to think of java as passing objects by reference, even though a) java doesn't pass objects at all and b) java doesn't do pass by reference. It passes object references by value.
    I've no idea what you're talking about wrt PreparedStatement, but String is immutable, so you can't change its state at all, so maybe that's what's tripping you up?
    Good Luck
    Lee
    PS: I will venture a guess that this is the 3rd reply. Let's see...
    Ok, second. Close enough.
    Yeah, good on yer mlk, At least I beat Jos.
    Message was edited by:
    tsith

  • How to create a dimension object in SAP BW Unv with Null value

    Hello,
    for query syncronisation task, I need a dimension object in my BW universe with NULL value. Does someone know, how to do it or if its possible?
    Regards,
    Thilo

    Hi Thilo,
    so the only common item is Material then - correct ?
    Query 1                                                                                Query 2
    Formulation (grouping of materials)                                                  (No counterpart)
    Material                                                                                Material
    dummy key figure (why?)                                                                Company Code
                                                                                    10 Keyfigure
    Is this something you regular have to do ? what about a MultiProvider ?
    did you try "merged dimensions" in the Web Intelligence Report ?
    Ingo

  • [SQL Server]Violation of PRIMARY KEY constraint 'DeploymentSummary_PK'. Cannot insert duplicate key in object 'dbo.DeploymentSummary'. The duplicate key value is

    I have migrated my SCCm 2007 environment to SCCM 2012 SP1 CU4.
    I noticed in the System Status\Component Status\SMS_STATE_SYSTEM a lot of errors like the one below:
    Microsoft SQL Server reported SQL message 2627, severity 14: [23000][2627][Microsoft][SQL Server Native Client 11.0][SQL Server]Violation of PRIMARY KEY constraint 'DeploymentSummary_PK'. Cannot insert duplicate key in object 'dbo.DeploymentSummary'. The duplicate key value is (1, 0, S0220438, 0). : spUpdateClassi
    Please refer to your Configuration Manager documentation, SQL Server documentation, or the Microsoft Knowledge Base for further troubleshooting information.
    When looking up the deployment ID and recreate the Deployment the problem is solved. But I have 700 packages and don't want to manually do this action on all packages. I think it is related to the migration i did and something went wrong there :-(
    Besides it will retriggers the deployment to the clients which is also not preferred.
    Is there another way to solve this by e.e.g do something directly in the SQL database tables ?

    Hi,
    It is not supported by Microsoft that do something directly in SQL database.
    If you want to do that, you could make a call to CSS.
    Best Regards,
    Joyce
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Multi-thread application recompile object with make but runs with old value

    Hi. I am working on a simulation in Java, and there is some behavior going on that I cannot understand. Granted, I'm a mechanical engineer, not a CS student (a fact that is probably made obvious by the code I'm posting below). The simulation comprises three parts: a controller, a robot, and a 3-d sensor. Here's the code for the "Simulation" application.
    class Simulation {
        void go() {
         ThreeDSensor sensorRunner = new ThreeDSensor();
         VSController controllerRunner = new VSController();
         KukaKR15SL robotRunner = new KukaKR15SL();
         Thread sensorThread = new Thread(sensorRunner);
         Thread controllerThread = new Thread(controllerRunner);
         Thread robotThread = new Thread(robotRunner);
         sensorThread.start();
         try {
             Thread.sleep(1000);  // Give sensorThread time to start in order to catch first triggers
         } catch(InterruptedException ex) {
             ex.printStackTrace();
         controllerThread.start();
         try {
             Thread.sleep(1000);  // Give controllerThread time to open the socket for communication with robotThread
         } catch(InterruptedException ex) {
             ex.printStackTrace();
         robotThread.start();
        public static void main(String[] args) {
         Simulation sim = new Simulation();
         sim.go();
    }I guess the big reason I'm using multi-threading is that once this simulation is working I want to be able to just run VSController alone and have it interface with a robot controller and a PC performing image processing. So with multiple threads I'm sending TCP and UDP messages around just like the final system will.
    I have made an object for my VSController that just stores values used by the simulation. That way I could have them all in one place instead of hunting through methods to change them. One example is "double noiseThreshold". Quickly, here is the code for "ControllerSettings.java".
    class ControllerSettings {
        final double cameraXOffset = 0;  // If > 0 then the origin of the camera CS is not on the center line of the lens
        final double cameraYOffset = 0;  // If > 0 then the origin of the camera CS is not on the center line of the lens
        final double cameraZOffset = 700;  // The distance that must be kept between the camera and the target
        // Error magnitude less than this is disregarded (in centimeters if roundingData else in millimeters)
        final double noiseThreshold = 60;
        final boolean estimatingEndPoints = false;  // If the controller is using two images per cycle then true
        final boolean roundingData = false;
        final boolean using3DData = true;  // How double[] sent from Matlab image processing is used
         * If the robot controller uses the output of this controller to command
         * motions in cartesian space then true.  This is used in two places: 1) initial guess of Jacobian,
         * and 2) "commandType" element sent to robot controller.
        final boolean useRobotControllerModel = false;
        final double thetaBumpValueForEstimationOfJacobian = .1;  // Distance each joint is jogged in estimation process
        final double bumpDistance = 50;  // Distance robot moves each time (magnitude of translation in mm)
        final double limitAngular = .5;  // Max amout robot joint will be commanded to rotate (in degrees)
    }And here is some pertinent code from "VSController.java".
    class VSController implements Runnable{
        ControllerSettings cSettings;  // Stores all the preferences used by the controller
        NGN controller;  // This is the controller algorithm.
        int dof;  // The degrees of freedom of the robot being controlled
        KukaSendData ksd;  // This provides communication to the robot.
        protected DatagramSocket socketForVisionSystem = null;
        ImageFeaturesData ifd;  // This parses and stores data from the image system.
        double[] errorVector;  // This is what's acted on by the algorithm
        PrintWriter errorTrackerOut = null;  // For analysis of error vector
        public void run() {
         VSController vsc = new VSController();
         vsc.go();
        public void go() {
         initWriters();
         cSettings = new ControllerSettings();
        public boolean isNoise() {
         boolean ret = false;
         double magnitude = 0;
         for (int i = 0; i < errorVector.length; i++) {
             magnitude += errorVector[i] * errorVector;
         magnitude = Math.sqrt(magnitude);
         if (magnitude <= cSettings.noiseThreshold) {
         System.out.println("VSController: magnitude (of errorVector) = " + magnitude +
                   ", threshold = " + cSettings.noiseThreshold); // Debug
    Now here's my issue: I change the value for "noiseThreshold" in "ControllerSettings.java" then run make from terminal (makefile code posted below) and rerun "Simulation". However, despite my changes to "ControllerSettings.java" the value for "noiseThreshold" is not changed, as evidenced by the output on the terminal screen:VSController: magnitude (of errorVector) = 6.085046125925263, threshold = 10.0 See, that value of 10.0 is what I used to have for noiseThreshold. I do not know why this value does not update even though I save the java file and execute make in between executions of Simulation. I would love it if someone could explain this problem to me.
    Here's the contents of makefile.
    JFLAGS = -cp ../Jama\-1\.0\.2.jar:../utils/:/usr/share/java/vecmath\-1\.5\.2.jar:.
    JC = javac
    .SUFFIXES: .java .class
    .java.class:
         $(JC) $(JFLAGS) $*.java
    CLASSES = \
         ControllerSettings.java \
         ImageFeaturesData.java \
         KukaKR15SL.java \
         ../utils/KukaSendData.java \
         NGN.java \
         Puma560.java \
         Robot.java \
         RobotSettings.java \
         Simulation.java \
         SimulationSettings.java \
         SixRRobot.java \
         Targets.java \
         TargetsSettings.java \
         ThreeDData.java \
         ThreeDSensor.java \
         VSController.java
    default: classes
    classes: $(CLASSES:.java=.class)
    clean:
         $(RM) *.classEdited by: raequin on Apr 5, 2010 1:43 PM

    I saw this explanation about what's causing my problem.
    "When the Java compiler sees a reference to a final static primitive or String, it inserts the actual value of that constant into the class that uses it. If you then change the constant value in the defining class but don't recompile the using class, it will continue to use the old value."
    I verified that the value updates if I also change something in VSController.java, forcing it to recompile. I think I will solve this problem by just making the variables in ControllerSettings no longer final (and then recompile VSController to make sure it takes effect!). Is there another solution? I saw intern(), but that seems to only apply to Strings.
    Thanks.

  • How much better is VBR 2 Pass than VBR 1 Pass or CBR?

    Hi,
    I had a 2 hour and 40 minute wedding on a Premiere Pro CS 5.5 Timeline. (I exported it as a QT Reference File from Final Cut Pro 7)
    I added my Encore Chapter markers in PPro and went File ----- Export ---- Media.
    Media Encoder opened and I set my settings the following way:
    H.264 Blu-Ray
    1440 x 1080 29.97 FPS
    PCM Audio
    Target Bit Rat = 18.5
    Max Bit Rate 20
    VBR 2 Pass
    When it first started encoding it said that it was going to take 8 hours.
    It has taken 14 Hours and it's finally finished.
    My question is,
    How much better is VBR 2 Pass than VBR 1 Pass or CBR?
    The first pass of this job took about 3 and a half hours. The last 11 hours was the full 2 Pass.
    Would VBR 1 Pass or CBR give a good enough quality as an H.264 Blu-Ray to give to clients.
    Thanks in advance
    Premiere Pro CS 5.5
    Media Encoder 5.5
    Encore 5
    Mac Pro
    10 GB RAM
    2.66 GHZ Quad-Core Intel Xeon

    Depends what you mean by "better". Multiple passes are done to reduce the file size (by more appropriate changes in bitrate for each moment in the footage). It's not designed to change the quality of the displayed frames, though it can have a small-but-noticeable quality effect on certain types of footage (e.g. a presentation that mixes static slides with high-motion video). If you can't see the difference in your footage, and you don't care about making the smallest possible file, VBR1 will get your clips done a lot faster.

  • *** [23000][2627][Microsoft][SQL Server Native Client 11.0][SQL Server]Violation of UNIQUE KEY constraint 'ClientPushMachine_G_AK'. Cannot insert duplicate key in object 'dbo.ClientPushMachine_G'. The duplicate key value is (16777412). : sp_CP_CheckNewAss

    *** [23000][2627][Microsoft][SQL Server Native Client 11.0][SQL Server]Violation of UNIQUE KEY constraint 'ClientPushMachine_G_AK'. Cannot insert duplicate key in object 'dbo.ClientPushMachine_G'. The duplicate key value is (16777412). : sp_CP_CheckNewAssignedMachine
    CCCRT::RunSQLStoredProc - Failed to execute SQL cmd exec [sp_CP_CheckNewAssignedMachine] N'xxx', 1
    CCRQueueRequest::GetRequestFromQueue - Failed to execute SQL cmd sp_CP_CheckNewAssignedMachine
    I get the above issue and the one below at a client site; the error started with the error below then changed to the one reported above and back to the one below. Everything is working as it should but the issues
    started when one of the admins at the data-centre incorrectly applied a gpo which affected a number of service accounts (sccm inclusive) and they expired....hence reporting in sccm got broke as well as this error in the ccm.log file appeared.
    Remote client install still works but I believe this error affects new client discovered by sccm, so in other words devices discovered by sccm do not get the client installed automatically....but if all access and permissions are in place...pushing out the
    client to the new discovered system works, it just not done automatically, which kinda defeats one the reasons for using sccm.
    I have searched the breadth of the tinternet and I can only find two technet reference to the same error  - one says to edit the stored procedure on the sql server which I don't think should be done... Like Jason said and I concur....its bad joo joos.
    The second suggestion, said you should select all the options in the Client Push Installation properties, I have tried this but hasn't solved the problem.
    I am planning to upgrade the site to the R2 CU3 before the end of the year but I would like to resolve this error before the upgrade.
    The site is currently sccm 2012 sp1 
    Any idea?> Resolution? sil vous plait!
    Merci

    Hi ,
    Please back up the database of the SCCM site. Then run the following query against the Site DB and see how it goes.
    DELETE FROM System_SMS_Resident_ARR
    WHERE ItemKey IN (
    SELECT ItemKey FROM vSystem_SMS_Resident_ARR
    GROUP BY ItemKey
    HAVING COUNT(ItemKey) > 1
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

  • Violation of PRIMARY KEY constraint 'PK_test'. Cannot insert duplicate key in object 'dbo.test'. The duplicate key value is (12610). (Source: MSSQLServer, Error number: 2627) ?

    Hi team,
    How resolve the below error 
    Violation of PRIMARY KEY constraint 'PK_test'. Cannot insert duplicate key in object 'dbo.test'. The duplicate key value is (12610). (Source: MSSQLServer, Error number: 2627) ?
    Thanks,
    Ram
    RAM

    Hi team,
    How resolve the below error 
    Violation of PRIMARY KEY constraint 'PK_test'. Cannot insert duplicate key in object 'dbo.test'. The duplicate key value is (12610). (Source: MSSQLServer, Error number: 2627) ?
    Thanks,
    Ram
    RAM
    There can be two reasons
    1. The insert script used is having multiple instances of the records with Key as 12610 returned from the source query. If this is the issue add a logic to include only the unique set of id values for records by avoiding duplicates. There are several approaches
    for this like using ROW_NUMBER with PARTITION BY, using a join with derived table etc
    2. The record with Key 12610 already exist in your destination table and your script is again trying to insert another instances of record with same key. This can be avoided by adding a NOT EXISTS condition with a subquery which will check and return only
    those records which doesnt already exist in the source
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • 1 pass VBR vs 2 pass VBR

    What's the difference? Trying to figure out some settings for this project, but not sure which one to choose. Any help is appreciated!

    The difference, in essence, is speed and accuracy.
    With one pass encodes, the encoder will move through the material just once examining the motion and estimating the best encode rate for each particular section, and for the settings you have put in place. It estimates, encodes and moves on.
    With two pass encoding, the first pass is used to analyse the motion and the second is the encoding - this is why the second pass takes so much longer. It is largely more accurate as it establishes the best encode for each section and then applies that on the second pass.
    Cinemacraft does multi-pass encoding, with each sweep refining the analysis made on the previous pass. Such a technique realy helps get the very best from the footage and this is why Cinemacraft is so highly thought of.
    However, the draw back is the time it takes... 2 pass takes longer than one pass, although the quality you get for the same (or similar) resulting file size, is better.

  • Passing Database Constant as a default value to EBS TCA API??

    My synch BPEL process calls EBS TCA (Trading Community Architecture) APIs via Apps Adapter to create and update Organizations (Parties) and Customers (Accounts) accordingly. TCA provides two types of APIs to do the same job - one uses record types and tables as parameters, while the other uses object types as parameters and is called Business Object(BO) API. I am using BO for my solution.
    One of the features of the Update API (hz_org_cust_bo_pub.*update*orgcust_bo) is you can pass a database constant (FND_API.G_MISS_CHAR) as a parameter value in order to nullify an existing value. Ex: AddressLine2 for a customer address has now changed and does not exists anymore. In order to update and existing value to NULL, you are required to pass one of the following constants as a parameter value.
    Following is a formal description of these optional parameter values from the TCA Reference document.....
    Optional IN parameters do not have default values. An attribute value that is not
    passed in is assumed to have a default of null for a Create API. For an Update API, if a
    particular attribute value is not passed into the API, then the database retains the
    existing value. In order to set a database value to null, the calling program must
    explicitly set the attribute value to one of the following constants, based on the data
    type of the attribute.
    +• FND_API.G_MISS_NUM for NUMBER type. (or FND_API.G_NULL_NUM)+
    +• FND_API.G_MISS_CHAR for VARCHAR2 type. (or FND_API.G_NULL_CHAR)+
    +• FND_API.G_MISS_DATE for DATE type. (or FND_API.G_NULL_DATE)+
    ISSUE:
    I am unable to pass and have the value FND_API.G_NULL_CHAR be treated as a constant by the API. When this value is passed by the BPEL process to the Apps Adapter (API) it gets passed as a string literal, as such, does not get treated as a database constant by the API. Also, on creating the apps adapter for this particular API (TCA BO) a wrapper program is NOT created. So, I can't modify the wrapper (as it does not exist) to pass this FND_API constant. The only option I can currently think of is to write my own custom PL/SQL package that calls the standard API and in turn have the custom package be called by the apps adapter. But, I am hoping this is not the only option, it takes away several benefits.
    Any thoughts will be greatly appreciated.
    ilyas

    I think that may be your only option. I haven't implemented this using the Apps Adapter but in order to get this functionality you need to have implmented the security architecture where you login as an Apps User, not APPS.
    I would raise a SR for this as this may be a bug.
    cheers
    James

Maybe you are looking for

  • HT2729 Having trouble video recording on my IPOD Touch 32 GB

    Can anyone help me with this problem? My IPOD Touch 32 GB won't video tape.  When I try to do a video tape it pauses. It will take pictures. Thank you. Barry

  • IPod touch froze up during restore

    I have been struggling with this issue since getting a refurbished Touch to replace one that got fed to my washing machine. I could not for the life of me get it to restore on my pc..kept geting error 9. It has something to do with USB ports I guess.

  • Hook not being executed before sysinit

    Hi, I'm trying a hook before sysinit but it's not working. I created a file called 'custom_hook' in /etc/rc.d/functions.d like this one: test_hook() {     /bin/echo 'it works' > /opt/testing add_hook sysinit_start test_hook But it does not execute be

  • I would like to downgrade from 6.0 to  5.1.1

    After I've got  6.0  I can't synchronize to the iTunes of my MAC. I need a firmware  5.1.1    iPhone 4

  • I upgraded and now it will not open

    I upgraded my iphoto and now I can not open it.  It told me to upgrade using the iphoto library upgrader,  I did and still not working..