Xml pass by reference

Hi,
Sorry if this is a little confusing...
We pass a clob into a stored proc, load it into a DOM, parse it and insert some data. We then get two NodeLists and pass those to another function within the same package. The following is recursive: For every node in the first node list, we insert some data into the db, get the new sid/id, send the new sid and second nodelist to another method and update the xml using xpath. However, when we come out of the updating method, the nodelist is unchanged. All parameters have a direction of IN OUT. I believe this is happening because the Java engine passes objects by value and not by reference. Is there any way around this?

Hi,
Sorry if this is a little confusing...
We pass a clob into a stored proc, load it into a DOM, parse it and insert some data. We then get two NodeLists and pass those to another function within the same package. The following is recursive: For every node in the first node list, we insert some data into the db, get the new sid/id, send the new sid and second nodelist to another method and update the xml using xpath. However, when we come out of the updating method, the nodelist is unchanged. All parameters have a direction of IN OUT. I believe this is happening because the Java engine passes objects by value and not by reference. Is there any way around this?

Similar Messages

  • Error in creation of Object Type from XML passed

    Hi,
    I am facing a problem creating a appropriate a object type for a XML.
    Below are the details:
    XML Passed
    <mer_offer_action_data>
    <form_id>
    134039588
    </form_id>
    <action_cd>
    OA
    </action_cd>
    <offer_decline_reason_cd>
    </offer_decline_reason_cd>
    <start_dt>
    </start_dt>
    <candidate>
    <ds_prs_id>
    109315
    </ds_prs_id>
    <ds_prs_id>
    110534
    </ds_prs_id>
    <ds_prs_id>
    110059
    </ds_prs_id>
    </candidate>
    </mer_offer_action_data>
    Types Declaration
    +CREATE OR REPLACE type MER_OFF_CANDIDATE
    AS
    OBJECT
    DS_PRS_ID NUMBER
    CREATE OR REPLACE TYPE MER_OFF_CANDIDATE_t
    AS
    TABLE OF MER_OFF_CANDIDATE;
    CREATE OR REPLACE type MER_OFFER_ACT_DATA
    AS
    OBJECT
    FORM_ID NUMBER,
    ACTION_CD VARCHAR2(6),
    OFFER_DECLINE_REASON_CD VARCHAR2(6),
    START_DT VARCHAR2(11),
    CANDIDATE MER_OFF_CANDIDATE_t
    CREATE OR REPLACE TYPE MER_OFFER_ACT_DATA_t
    AS
    TABLE OF MER_OFFER_ACT_DATA;
    CREATE OR REPLACE type MER_OFFER_ACTION_DATA
    AS
    OBJECT
    MER_OFF_ACT_DATA MER_OFFER_ACT_DATA_t
    /+
    My Declaration
    +merOffActDataXML      xmltype;
    merOffActData     MER_OFFER_ACTION_DATA := MER_OFFER_ACTION_DATA(MER_OFFER_ACT_DATA_t());+
    Inside Pl/SQL block
    +-- Converts XML data into user defined type for further processing of data
    xmltype.toobject(merOffActDataXML,merOffActData);+
    when I run the Pl/Sql block it gives me error
    ORA-19031: XML element or attribute FORM_ID does not match any in type ORADBA.MER_OFFER_ACTION_DATA
    which means the object type mapping is wrong
    I would like to know whether the object type I had created is correct or not.
    Thanks for your help
    Beda

    Bedabrata Patel wrote:
    Below are the details:The details except for a description of the problem
    I am facing a problem creating a appropriate a object type for a XML.And which error you are getting
    Error in creation of Object Type http://download.oracle.com/docs/cd/E11882_01/server.112/e10880/toc.htm
    And which version of Oracle you are getting the unknown error creating the unknown problem.

  • How do you pass vi references from one event to another

    I have a vi which gets vi references (thereby loading the vi's into memory) for all the vi's in a given directory when a user clicks a button on the front panel. To do this I use an event structure. My question is whether it is possible to have another event (user button on the front panel) which unloads the vi's from memory. I have tried passing the vi references that are initially generated to the close reference function but whenever I do I get a 'vi reference invalid' error. Does this have to do with trying to pass the vi references between one event and another? If I use a local variable simply pass a reference to another indicator and then probe it, the originally-generated refnum and the local vari
    able refnum match up. However once I try to wire that same indicator to the close reference function I get the 'vi reference invalid' error. Is there a different/better way to unload the vi's from memory based on a user button click? Any suggestions would be welcome.
    Jason
    Attachments:
    Load_Directory_of_vi's.vi ‏57 KB

    Several problems with your code:
    1... Bad idea to use lights as buttons. Yes it can be done, but it's not "natural".
    2... If you've gotta do that, set their mechanical action to "LATCH WHEN RELEASED"
    3... Because of #2, you are getting TWO copies of every array when you click the LOAD VIs light (er... button).
    4... No need for the conversion from path to string and back - use BUILD PATH to append each file name to he folder path.
    5... Set the BROWSE OPTIONS on your PATH control to EXISTING DIRECTORY to allow browsing of directories, not files.
    6... Your code doesn't care whether the file is a .VI file, or a .ZIP file, or a .TXT file, or what. Use the PATTERN input on the LIST function to discriminate.
    7... Your code is only storing the latest refer
    ence, not the array of references.
    8... An ERROR DIALOG on the OPEN REFERENCE function will tell you that you're getting an error. Why? You are asking to prepare a non-reentrant VI for reentrant execution (why use options = 8?)
    9... Because of #8, the latest VI reference is invalid.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

  • Drag and Drop - Transferable, how to pass a reference? (URGENT)

    I've a tree that supports drag and drop correctly but every time I exchange a node position the old parent instance remaining on the tree is different from the one I was referencing with the dragged child before the drag occurred. I absolutely need to maintain all references and cannot work with copies.
    Is there any way to use the Transferable interface to pass the original object instead of a copy?
    Thanks to Tedhill who raised the problem, trying to get a quick answer.
    ;o)

    hi guys let me close this thread:
    Thanks to asjf and sergey35 who helped me.
    Actually the isDataFlavorSupported method you suggest passes a reference and not a copy.
    Too bad I fell into another problem with the reloading of the
    moving-node Object after the DnD.
    But finally the working code is:
    public class XJTreeDnD extends XJTree implements DragGestureListener, DragSourceListener, DropTargetListener{
      private DefaultMutableTreeNode dragNode = null;
      private TreePath dragParentPath = null;
      private TreePath dragNodePath = null;
      private DragSource dragSource;
      private DropTarget dropTarget;
      private TransferableTreePath transferable;
      private boolean DnDEnabled = true;
      //private boolean CnPEnabled = false;
      public XJTreeDnD(XNode node) {
        super(node);
        // Set up the tree to be a drop target.
        dropTarget = new DropTarget(this, DnDConstants.ACTION_MOVE, this, true);
        // Set up the tree to be a drag source.
        dragSource = DragSource.getDefaultDragSource();
        dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_MOVE, this);
      private DefaultMutableTreeNode getTreeNode(Point location) {
        TreePath treePath = getPathForLocation(location.x, location.y);
        if (treePath != null) {
          return((DefaultMutableTreeNode) treePath.getLastPathComponent());
        } else {
          return(null);
    //dragGesture implementation
        public void dragGestureRecognized(DragGestureEvent e) {
          if(DnDEnabled){
            TreePath path = this.getSelectionPath();
            if (path == null || path.getPathCount() <= 1) {
              System.out.println("Error: Path null, or trying to move the Root.");
              return;
            dragNode = (DefaultMutableTreeNode) path.getLastPathComponent();
            dragNodePath = path;
            dragParentPath = path.getParentPath();
            transferable = new TransferableTreePath(path);
            // Start the drag.
            e.startDrag(DragSource.DefaultMoveDrop, transferable, this);
    //dragSource implementation
        public void dragDropEnd(DragSourceDropEvent e) {
          try {
            if (e.getDropSuccess()) {
              ((BaseXJTreeModel)this.getModel()).removeNodeFromParent(dragNode);
              DefaultMutableTreeNode dragParent = (DefaultMutableTreeNode) dragParentPath.getLastPathComponent();
              XNode xnodeParent = (XNode)dragParent.getUserObject();
              ((BaseXJTreeModel)this.getModel()).valueForPathChanged(dragParentPath, xnodeParent);
          } catch (Exception ex) {
            ex.printStackTrace();
        public void dragEnter(DragSourceDragEvent e) {
          // Do Nothing.
        public void dragExit(DragSourceEvent e) {
          // Do Nothing.
        public void dragOver(DragSourceDragEvent e) {
          // Do Nothing.
        public void dropActionChanged(DragSourceDragEvent e) {
          // Do Nothing.
    //dropTarget implementation
        public void drop(DropTargetDropEvent e) {
          try {
            Point dropLocation = e.getLocation();
            DropTargetContext dtc = e.getDropTargetContext();
            XJTreeDnD tree = (XJTreeDnD) dtc.getComponent();
            TreePath parentPath = tree.getClosestPathForLocation(dropLocation.x, dropLocation.y);
            DefaultMutableTreeNode parent = (DefaultMutableTreeNode)parentPath.getLastPathComponent();
            Transferable data = e.getTransferable();
            DataFlavor[] flavors = data.getTransferDataFlavors();
            for (int i=0;i<flavors.length;i++) {
              if (data.isDataFlavorSupported(flavors)) {
    e.acceptDrop(DnDConstants.ACTION_MOVE);
    TreePath movedPath = (TreePath) data.getTransferData(flavors[i]);
    DefaultMutableTreeNode treeNodeMoved = (DefaultMutableTreeNode) movedPath.getLastPathComponent();
    DefaultMutableTreeNode treeNodeLeft = (DefaultMutableTreeNode) this.dragNodePath.getLastPathComponent();
    XNode xnodeParent = (XNode)parent.getUserObject();
    XNode xnodeChild = (XNode)treeNodeLeft.getUserObject();
    /** @todo check the parent whether to allow the drop or not */
    if(xnodeParent.getPath().startsWith(xnodeChild.getPath())){
    System.out.println("cannot drop a parent node on one of its children");
    return;
    if(xnodeParent.getPath().getPath().equals((xnodeChild.getPath().getParentPath()))){
    System.out.println("node is already child of selected parent");
    return;
    // Add the new node to the current node.
    xnodeParent.addChild(xnodeChild);
    ((BaseXJTreeModel)this.getModel()).valueForPathChanged(parentPath, xnodeParent);
    ((BaseXJTreeModel)this.getModel()).insertNodeInto(treeNodeMoved, parent, parent.getChildCount());
    ((BaseXJTreeModel)this.getModel()).valueForPathChanged(movedPath, xnodeChild);
    e.dropComplete(true);
    } else {
    System.out.println("drop rejected");
    e.rejectDrop();
    } catch (IOException ioe) {
    ioe.printStackTrace();
    } catch (UnsupportedFlavorException ufe) {
    ufe.printStackTrace();
    public void dragEnter(DropTargetDragEvent e) {
    if (isDragOk(e) == false) {
    e.rejectDrag();
    return;
    e.acceptDrag(DnDConstants.ACTION_MOVE);
    public void dragExit(DropTargetEvent e) {
    // Do Nothing.
    public void dragOver(DropTargetDragEvent e) {
    Point dragLocation = e.getLocation();
    TreePath treePath = getPathForLocation(dragLocation.x, dragLocation.y);
    if (isDragOk(e) == false || treePath == null) {
    e.rejectDrag();
    return;
    // Make the node active.
    setSelectionPath(treePath);
    e.acceptDrag(DnDConstants.ACTION_MOVE);
    public void dropActionChanged(DropTargetDragEvent e) {
    if (isDragOk(e) == false) {
    e.rejectDrag();
    return;
    e.acceptDrag(DnDConstants.ACTION_MOVE);
    private boolean isDragOk(DropTargetDragEvent e) {
    /** @todo gestire i casi in cui il drop non sia concesso */
    return (true);
    public void setDragAndDropEnabled(boolean enabled){
    this.DnDEnabled = enabled;
    public boolean isDragAndDropEnabled(){
    return this.DnDEnabled;
    Thanks again.
    flat

  • Passing model reference to a page in a Popup

    Hi all,
    I have a BSP Application with MVC. In a view I want to open a new window when clicking in an input field with a JavaScript function:
    function openCatalog (inputField, inspchar) {
        adresse = "catalog.htm";
        document.formInsertMerkmal.fieldname.value = inputField;
        view = window.open(adresse, "Katalogauswahl", "width=400,height=400,left=100,top=200");
        view.focus();
    The catalog.htm is a bsp page with logic in the same application. Opening and closing this page is no problem.
    But how can I pass the reference to the model from the first view, eg. start.htm to the new page catalog.htm. I want to read data from the model and write data back to model attributes.
    Can I pass the modelreference in the url? And how do I read the model in the new window?
    In start.htm I declared the model in the page attributes and can access data from model.
    What Stepps are necessary to do the same in the new window. I don’t want to raise an event in the controller to go to a next page.
    Please help!

    Hi Raja,
    I just begin to develop with BSP. I don't understand exactly  what I must do :
    "in the method IF_BSP_APPLICATION_EVENTS~ON_START instantiate your model class and pass the instantiate model class reference to a attribute of the application class.
    now this can be referenced in the all the pages with application->applicationclassattribute for model."
    You can do an example source code, please.
    Thanks you very much for help.
    Lionel

  • Org.xml.sax.SAXParseException: Reference is not allowed in prolog

    Hi,
    I have been using DocumentBuilder to parse an xml string in our application but now came up with this exception:
    org.xml.sax.SAXParseException: Reference is not allowed in prolog
    When I looked at the xml data, I found that it does not have a prolog in it. I also found that the data contains end of line character ""&#xD;""
    " in it.
    This the xml to be parsed: (Qutoted them to view the unicodes in xml)
    "<dc:dc xmlns:dc="http://purl.org/dc/elements/1.1/">
    <dc:title xml:lang="en">Test metadata</dc:title>
    <dc:language>en</dc:language>
    <dc:description xml:lang="en">Blah</dc:description>
    <dc:creator>BEGIN:vcard
    FN:Jan Austin
    ORG:IBalahblahLtd
    EMAIL:[email protected]
    END:vcard</dc:creator>
    <dc:format>text/html</dc:format>
    <dc:identifier>http://gg.com/</dc:identifier>
    <dc:subject>Medicine and Dentistry</dc:subject>
    </dc:dc>"
    And in the class, I used,
    DocumentBuilderFactory factory =  DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(file);I can not change the xml data to be parsed as the application gets this data from other targets through a web service.
    So, can anyone provide any suggestions to solve this issue please?
    Thanks,
    Shiv.

    I have tried various options by
    1. factory.setIgnoringElementContentWhitespace(true);
    2. factory.setValidation(false);
    But, none of them seems to work.
    Could anyone please giv me atleast a gist abt where to look about?
    Cheers,
    Shiv.

  • Passing a reference to a type definition to a SubVI

    I have created a type definition that I would like to use across my application. This particular type definition is also the front panel control to my top level VI. I wanted to pass a reference to this control to my SubVi's so that they could dereference as needed and in very rare cases update the values on the front panel. However, as I built the application I noticed that I was breaking the control reference as I updated the type definition. This implies that they type of the reference changes as I change the type definition.
    How do I go about building the reference I need or is there some other way to do this that works just as well. Even if I can't make a reference to the control that is tied to the type definition, I'm willing to pass in a variant who can house the reference as long as I can build the data type (the reference) inside my SubVis.
    Solved!
    Go to Solution.

    Okay, so I tried all three approaches in a SubVI, here's what happened.
    My approach was simply to create a Type Def control, right-click and create a Reference. Then create a control from that reference by right-clicking the output of the reference and selecting the Create Control option. I then pasted this 'cluster' reference into my SubVi, made it an input and then wired up the reference in the parent to the control in the SubVi.
    Result: This breaks when you update the Type Definition.
    Next, Ben's approach (or my best effort at doing what he suggested). I created a control from reference to the type def. I cut it from the parent VI and pasted it into a new type def. I then put the type def in the SubVI and set it as an input.
    Result: This breaks when you update the Type Definition (but it actually takes a bit longer for the error to propogate).
    Finally, Christian's solution (or my best effort). I took the type def reference and put it through a To More Generic Class guy, casting it to a Control Refnum. I put a Control Refnum on the front panel of my SubVI and wired it to a To More Specific Class guy. I created a control of the type def in the subvi, hid it, and created a reference. I wired the reference to the more specific guy and verified I was getting the right data.
    Result: It works!
    It's possible I just didn't understand how to make the reference type def you were referring to Ben. I would prefer a method with less verbage. I pass this refnum into a class which holds it. Since I can't replicate the type exactly prior to run time (i.e. create a control that is exactly a reference to the type definition of my front panel), I have to save the reference as a Control Refnum and cast it every time I need it (i.e. create a control from the typedef, create a reference frome the type def, etc). More verbage than optimal, but still good!
    Thanks for the help.

  • 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

  • Passing a reference / variable to a Custom Component

    Hi, I was wondering if someone could help me.
    It seems like a very simple problem but I cant for the life
    of me seem to work out a solution.
    I have created a Custom Component that extends from the
    UIComponent that consists of a “rev counter” style
    clock face etc….
    I want to use this component multiple times within my
    application – however feed it different data so for example
    each “rev counter” on the page will be displaying
    different data etc…..
    I want to be able to reuse my component and not have to
    create a new component every time I add a “rev counter”
    to my application, therefore I need some way of passing a reference
    / variable to the component (maybe from the <mx /> tag where
    I declare it in the MXML code ??? )
    <mx:Application ….
    xmlns:comps="components.*" …..>
    <comps:RevCounterComp id=”” (add something
    here to reference???) />
    </ mx:Application>
    Doing this will allow me to reuse my ONE custom component
    MANY times feeding it different data (different data provaiders for
    each instance of the single component)
    Hope this makes sense???
    Any help / advice is much appreciated,
    Thanks,
    Jon.

    Jon,
    jmryan's suggestion is the preferred way to go. This way you
    can use the simple MXML syntax that you described in your post.
    If your custom component is defined in ActionScript, you can
    use setters or the creationComplete event to update the component
    when the values are passed in from the tag (they are set *after*
    your constructor runs).
    Even easier, if your component is defined in MXML, you can
    add [Bindable] to your public field and then bind directly to it in
    the custom component's MXML code.
    - Peter

  • Passing control reference to subVI crashes labview

    Hi,
    using a image control (as indicator) provided by imaq Vision, I tried to pass the reference of the control to a subVI. On a computer it works and on a other (same labview version, same vision version, same os, same hardware and hardware drivers!), this crashes labview. I tried to close the control refnum at the end of the subVI, but that changed nothing to the issue. Now I use the reference as a global variable and it seems to work...nevertheless, I would like to understand what the issue and if I should remove any passing to subVI of control ref because this can potentially triggers an error. My correlated question is if this global passing is a "fake" workaround or have real chance of improving (this before going through the whole code for changing all passing of reference to subVI)
    thanks a lot

    Hi,
    thank CoastalMaineBird for your answer
    How do you know it's this issue which causes the crash?
    When I remove this parameter from and the only property node in the subVi that write to it, I have no longer any problem. Moreover, to ensure that's really the "passing", and made a global variable containing the reference to this control and use my original SubVi that do access the control through its reference number
    , and it works! In this last exemple, the only change is the way of transmitting the reference
    What LabVIEW version?
    8.0.1
    up to date according Measurement & Automation update tool
    Given that one computer works OK, and another crashes, I would say that
    you are seeing the effect of something else, not the cause. If passing
    a control ref via terminals was fatal, it would be fatal all the time.
    You have some other sort of issue, perhaps timing of the different
    machines triggers the bug, perhaps running out of memory, perhaps
    LabVIEW is corrupted on one machine.... But I don't think changing all
    your code to use globals would solve the real problem. Actually, saying that I wonder about problem of synchronisation. I know from Visual C++ that this kind of error happens if two process try to access the same control at the same time. This is typically an error changing from a computer to an other, and mutex or semaphore are the way to deal nicely with that. But does labview contains already such a securisation? If so, the global variable point on a single object and can "fell" the semaphore/mutex. But passing make a copy that will likely have two different semaphore/mutex but will point to a single control! Do someone know if I'm wrong in this idea or not?
    Thanks

  • Passing object references to methods

    i got the Foo class a few minutes ago from the other forum, despite passing the object reference to the baz method, it prints "2" and not "3" at the end.
    but the Passer3 code seems to be different, "p" is passed to test() , and the changes to "pass" in the test method prints "silver 7".
    so i'm totally confused about the whole call by reference thing, can anyone explain?
    class 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;
    class Passer2 {
         String str;
         int i;
         Passer2(String str, int i) {
         this.str = str;
         this.i = i;
         void test(Passer2 pass) {
         pass.str = "silver";
         pass.i = 7;
    class Passer3 {
         public static void main(String[] args) {
         Passer2 p = new Passer2("gold", 5);
         System.out.println(p.str+" "+p.i);  //prints gold 5
         p.test(p);
         System.out.println(p.str+" "+p.i);   //prints silver 7
    }

    private static void baz(Foo foo) {
    foo.bar = 2;
    foo = new Foo();
    foo.bar = 3;This sets the bar variable in the object reference by
    foo to 2.
    It then creates a new Foo and references it by foo
    (foo is a copy of the passed reference and cannot be
    seen outside the method).
    It sets the bar variable of the newly created Foo to
    3 and then exits the method.
    The method's foo variable now no longer exists and
    now there is no longer any reference to the Foo
    created in the method.thanks, i think i followed what you said.
    so when i pass the object reference to the method, the parameter is a copy of that reference, and it can be pointed to a different object.
    is that correct?

  • How to pass file reference to c

    Hi,
    I want to pass file reference pointer to a dll written in visual c++. How can i do that?

    What do you want to do with that reference in your C code? if you want to access it using OS File IO functions you have to be very careful! You should not mix LabVIEW nodes and OS platforms calls together. It's either one or the other.
    If you can guarantee that what you want to do is configure the Call Library Node (CLN) parameter to Adapt To Type. Then right click on the CLN and select "Create C Source Header" or something to that meaning. Save the resulting file to disk. Open it and copy the function prototype into your C/C++ file. There should be a parameter typed LVRefnum *. Now you can use the LabVIEW manager C function MgErr FRefNumToFD(LVRefNum refNum, File *fdp);
    You need to link your DLL with labview.lib in the cintools directory in order to be able to call the FRefNumToFD() function. The value in the fdp reference is the platform specific file handle, so for Windows this is a HANDLE.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • What is the use of passing object reference to itself ?

    What is the use of passing object reference to itself ?
    regards,
    namanc

    There is an use for returning an object reference from itself, for instance:
    class C {
    public:
         C append(C c) {
             // do something interesting here, and then:
             return this;
    }You can "chain" calls, like this:
    C c = new C();
    C d = new C();
    C e = new C();
    c.append (d).append (e);Maybe the OP has "inverted" the common usage, or thought about a static method of a class C that requires a parameter of type C (effectively being a sort of "non-static method").
    class C {
        static void doAnotherThing (C c) {
            c.doSomething(); //-- effectively C.doAnotherThing(c) is an "alternative syntax" for c.doSomething()

  • Pass by reference and String

    public class Test {
        static void method(String str) {
            str = "String Changed";
        public static void main(String[] args) {
            String str = new String("My String");
            System.out.println(str);
            method(str);
            System.out.println(str);
    }The output is
    My String
    My String
    How this is possible when objects are passed by reference ?

    > How this is possible when objects are passed by reference ?
    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.
    ~

  • Pass-by-reference?

    Please tell me if I am wrong and explain how it actually works!
    But i think there is pass-by-reference..
    Part of Frame.java
    SplashPanel splashpanel = new SplashPanel(this);Part of SplashPanel.java
    public class SplashPanel extends JPanel{
         private Frame frame;
         public SplashPanel(final Frame frame) {
              this.frame = frame;I am newbie in Java and programming at all, so sorry if i am wrong.

    That's not pass by reference. That's passing a reference by value.
    Primitives are passed by value.
    References are passed by value.
    Objects are not passed at all--not by reference, not by value.
    Java is always pass-by-value. Always.
    Always. Always. Always.
    http://javadude.com/articles/passbyvalue.htm
    http://java.sun.com/developer/JDCTechTips/2001/tt1009.html#tip1
    http://www.javaranch.com/campfire/StoryPassBy.jsp
    http://www.javaworld.com/javaworld/javaqa/2000-05/03-qa-0526-pass.html
    http://www-106.ibm.com/developerworks/library/j-praxis/pr1.html
    http://www.cs.toronto.edu/~dianeh/tutorials/params/
    http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#38698
    http://radio.javaranch.com/channel/val/2004/05/21/1085125887000.html
    There is exactly one parameter passing mode in Java -- pass by value -- and that helps keep things simple.
    -- James Gosling, "The Java Programming Language, Second Edition"
    (James Gosling being the father of Java)

Maybe you are looking for

  • [Solved] Spanish characters not read on NTFS hard drive

    Hi there, Every time I mount my NTFS hard drive with the windows partition on it, I can't read the file names properly. Instead of á, é, í, ó and ú it introduces boxes or interrogation signs. Any idea why that may be? Last edited by Zespris (2008-11-

  • Storing imovie projects for re-use

    Hi there, Could anyone tell me the best way to store my imove 06 projects so that in time I can re-use the footage to create and edit movies later? I have imported my video footage into projects using imovie. Each project only contains footage for th

  • How to run the jsp programs

    hi how to develop the html and jsp 's using eclipse IDE what are the steps to follow inorder to develop and run the jsp's using Eclipse IDE

  • Need to Upgrade current Mac OS 10.3.9 - Tiger or Leopard

    I am looking for advice - Need to update Mac OS x. Should I go with Tiger or Leopard? I have read several negative issues about Leopard not being ready for 'prime time'. Want to have a seamless upgrade with minimum downtime. Plus, read that Leopard d

  • Bridge and external Antennas

    I am trying to setup 2 1240ap in a bridge mode using external antennas. I am wonder how you line up the antennas to obtain the best signal. I know the 1300 series has software that allows you to see a signal as you line up the antennas, but I don't t