By copy and by reference

Hello,
What is the difference between "by copy" and "by reference" ? How can I show their difference?
Regards,
V~.~!

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 vecause 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 mod -- pass by value -- and that helps keep things simple.
Reference:
Arnold, K., Gosling J., Holmes D. (2000). The Java� Programming Language Third Edition. Boston: Addison-Wesley.

Similar Messages

  • Is it possible to copy and paste a formula without changing the cell references?

    I am trying to paste a formula to a cell adjacent to where it currently is but when I do, the cell references in it change. I am trying to get exactly the same formula in the cell (without re-typing it).

    dedwards96 wrote:
    Just another quick question, is it possible to make a large number of cell references 'absolute'?
    Individual cell references in formulas may have four distinct states: relative, absolute column, absolute row, or absolute column and row. These are set using the popup menu on the reference itself. Click on the reference in the formula and choose one of the four states from the popup menu.
    Once set, you can fill the formula into the rest of a column or row using the Fill Handle (small circle at the lower right of a selected cell). Cell references in the new copies of the formula will remain absolute or adjst to their new position dependent on the setting for each reference. You can also copy and paste the cell (single click to select it, command-C to copy) with the same results.
    You can also copy/paste without changing the formula's cell references if you select the formula (Drag across the formula in the entry bar, copy, press tab to deselect and reconfirm the formula in the original cell) rather than the cell. Pasted into a new cell, the formula will appear as if you typed it in exactly as it was in the original cell—neither absolute references nor relative references will have changed.
    Regards,
    Barry

  • [b]HOW TO:[/b]  Copy and Paste THE Filename AND its PATH from Finder

    HOW TO DO THIS: Copy and Paste THE selected Filename AND its entire PATH from Finder to another application as in document footer reference, or document database which has a path field to aid in locating the file later.
    Finder, Spotlight and File Info (can be used to display Path) or using Command F, command I, etc. but user is not allowed to copy the path to clipboard.
    This is rudimentary, yet the word Path, is unknown to Mac Help.
    Message was edited by: jbov

    AJ,
    Isn't it amazing....There is no Command Key for this action? Apple Care was confounded too. And thanx, it'll be a help....
    Jim
    its tedious, but this should work:
    open a terminal window.
    Drag and drop the icon for the file in the terminal
    window.
    This will put the full path including the filename on
    the command line.
    Copy the path from the command line, and paste
    (wherever).
    Close the terminal window.

  • Is it possible to restrict copying and printing a pdf?

    Is it possible to restrict copying and printing a pdf without setting a password? I just want to restrict using the document, but don't want a password-demanding window to pop up.

    Hei guys!
    I truly need your reply!
    Any reply or a hint or a reference to another application is welcome.
    Thank you!

  • Item 000002 is not copied from the reference document

    Dear All,
    I am facing a typical problem while creating Price difference sales order w.r.t. invoice.
    Document types in the system are -
    Z2FC - Normal Sales order type, ZPD - Price change order type, Z2FB - Normal invoice type
    My item category determination is -
    Doc. type -  Itm cat. gp.  -  Usage - Hghr itm cat - Default itm cat. - Manual itm. cat.
    ZPD         -   NORM         -  blank   - blank           -  G2N                  - L2N
    ZPD         -   NORM         -  blank   - G2N            -  G2N                  - L2N
    Z2FC       -   NORM         -  blank   - Blank           - TAN                  - TAP
    Z2FC       -   NORM         -  blank   - TAN            - TANN                - TAN
    Copy control is -
    Z2FB to ZPD for item category TAN with proposed item categories are G2N and L2N.
    Z2FB to ZPD for item category TANN u2013 requirement 302 [Do not copy item]
    During my Z2FC sales order creation I was having line items as follows
    Item no. -  Mat. code     -  Qty -      Higher level item - Item category - Amount
    10         -  101329          -  3     -      blank                 - TAN                - 35,000.00
    20         -  MC091234    -  3     -      10                      - TANN             - 0
    30         -  MC091234    -  1     -      10                      - TAN                - 5000
    We are not using the sales BOM. I need to provide line 20 free to the customer. Hence I have manually maintained 10 in the higher level item column for the line item 20. The item category determined was TAN. Then I had changed it to TANN manually. So the amount became zero. Line 20 became the child and line 10 became parent.
    At the same time customer also wishes to buy the material code MC091234. Now the material code MC091234 is of HALB type where as the material code 101329 is of FERT type. There is validation in the system that only FERT type of material could be sold and HALB type of material could be supplied as free. [With item category TANN]. In case HALB type material is also required to be sold then I need to manually maintained value in the higher level item. So I had maintained the value 10 in the higher level item column for the line item 30. The default item category determined is TAN. The invoice is also created properly. [Z2FB type]
    But when I am creating the invoice correction document type ZPD w.r.t. Z2FB type invoice, I am able to get the two line items for the material code 101329 in line item 10. One each for G2N and L2N item category.
    But for the material code MC091234 in line item 30, I get only one line item with item category G2N. I did not get another line item for the material code MC091234 for the corresponding L2N type item category
    At the same time following messages are displayed
    Message no. V1475 Item category for item 000002 cannot be determined and
    Message no. V1476 Item 000002 is not copied from the reference document
    Please help.
    Thanks in advance
    Piyush Ranpura

    Dear All,
    Any help???
    Yet my issue is unresolved.
    Thanks & Regards
    Piyush Ranpura

  • How to cut, copy and paste a tree node in JTree?????

    Hi, Java GUI guru. Thank you for your help in advance.
    I am working on a File Explorer project with JTree. There are cut, copy and paste item menus in my menu bar. I need three EventAction methods or classes to implements the three tasks. I tried to use Clipboard to copy and paste tree node. But I can not copy any tree node from my tree.
    Are there any body has sample source code about cut, copy, and paste for tree? If possible, would you mind send me your sample source code to [email protected]
    I would appreciate you very very much for your help!!!!
    X.G.

    Hi, Paul Clapham:
    Thank you for your quick answer.
    I store the node in a DefaultMutableTreeNode variable, and assign it to another DefaultMutableTreeNode variable. I set up two classes (CopyNode and PasteNode). Here they are as follows:
    //CopyNode class
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    public class CopyNode implements ActionListener{
    private TreeList jtree;
    String treeNodeName;
    TreePath currentSelection;
    DefaultMutableTreeNode currentNode;
    public CopyNode(TreeList t){
    jtree = t;
    public void actionPerformed(ActionEvent e){
    currentSelection = jtree.tree.getSelectionPath();
    if(currentSelection != null){
    currentNode = (DefaultMutableTreeNode)(currentSelection.getLastPathComponent());
    treeNodeName = currentNode.toString();
    //PasteNode class
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    public class PasteNode extends DefaultMutableTreeNode{
    private TreeList jtree;
    CopyNode copyNode;
    public PasteNode(TreeList t){
    jtree = t;
    copyNode = new CopyNode(t);
    public DefaultMutableTreeNode addObject(Object child){
    DefaultMutableTreeNode parentNode = null;
    TreePath parentPath = jtree.tree.getSelectionPath();
    if(parentPath == null){
    parentNode = jtree.root;
    else{
    parentNode = (DefaultMutableTreeNode)parentPath.getLastPathComponent();
    return addObject(parentNode, child, true);
    public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent, Object child, boolean shouldBeVisible){
    DefaultMutableTreeNode childNode = copyNode.currentNode;
    if(parent == null){
    parent = jtree.root;
    jtree.treemodel.insertNodeInto(childNode, parent, parent.getChildCount());
    if(shouldBeVisible){
    jtree.tree.scrollPathToVisible(new TreePath(childNode.getPath()));
    return childNode;
    I used these two classes objects in "actionPerformed(ActionEvent e)" methods in my tree:
    //invoke copyNode
    copyItem = new JMenuItem("Copy");
    copyItem.addActionListener(copyNode);
    //invoke pasteNode
    pasteItem = new JMenuItem("Paste");
    pasteItem.addActionListener(
    new ActionListener(){
    public void actionPerformed(ActionEvent e){
    pasteName.addObject(copyName.treeNodeName);
    When I run the drive code, making a copy some node from my tree list, I got bunch of error messages.
    Can you figour out what is wrong in my two classes? If you have sample code, would you mind mail me for reference.
    Thank you very much in advance.
    X.G.

  • Copy and Paste Spreadsheet in Numbers 3.0 to Pages 5.0

    I have a spreadsheet that I need to copy from Numbers 3.0 into Pages 5.0. I have tried to copy and paste to no avail. I have exported as a .pdf and it is blurry when I paste it into the pages document. Does anyone know how I can get this spreadsheet into my Pages 5.0 document?

    Hi Hans,
    I can get a reference error here if the destination table does not have that range available while the source table does. 
    Are you sure your desination table has exactly the same structure and dimensions as your source table?
    If it does, copy/paste via the Formula Editor should work. It works reliably here.
    Also the formula in your latest post looks as if it might be corrupted-- lots of extra spaces (it seems).  Did your orginal formula have those?
    To sort this out, suggest turning off 'Use header names as labels' in Preferences.
    If you end up with a formula in a cell as just Text (as Ian describes that's what happens when you copy from Numbers 2) you can convert that text to a formula by double-clicking the cell, clicking just before the text so that the insertion point appears in front of it and typing =. That activates the Formula Editor with the formula in it, which you can accept by clicking the green checkmark or hitting return.
    SG

  • TOC and Cross reference bookmarks

    Hi. I recently finished work on a book that had front matter containing a brief TOC and a detailed TOC. The book also contained individual TOCs at the beginning of each chapter.
    I updated all numbering across the book files before generating the TOCs in the front matter, then generated the brief and detailed TOCs using my TOC Styles. However, I assigned cross references for the individual chapter TOCs. May not have been the best choice.
    Because there was special styling for some of the front matter TOC entries that wasn't easily specified using just the TOC Styles, I cut and pasted groups of entries from the generated TOC on the pasteboard into a new frame on the page. I checked in Story Editor to ensure that the invisible markers for the TOC entries had been copied into the new frame.
    When I exported the files to PDF, the TOC entries no longer pointed to the correct pages. They simply pointed to the first page of the PDF when clicked. Furthermore, no bookmarks showed up the TOC entries in the Bookmarks panel, even though I had "Create PDF Bookmarks" checked in my TOC Styles.
    I have three questions, then:
    --Is there any way to reclaim the behavior of the TOC bookmarks, and their display in the Bookmarks list of the PDF, if the entries are copied and pasted into a new frame in InDesign, without doing this manually in Acrobat Pro?
    --Is there any way to get cross references to display as bookmarks in a PDF, assuming that I needed to make individual PDFs of each chapter, without doing this manually in Acrobat Pro?
    --I'm betting that all files should be exported from InDesign as a single PDF in order for all TOC and cross reference links to work properly, without manual intervention in Acrobat Pro? If so, and manual intervention is required, is this accomplished by cataloging/indexing in Acrobat Pro?
    I need to be able to pass this information along to a publisher who is now requiring all of their compositors to submit bookmarked PDFs with their printer files. I'm pretty sure I know the answer to this one, but I would like verification from the pros here. Thanks!

    Hi. I recently finished work on a book that had front matter containing a brief TOC and a detailed TOC. The book also contained individual TOCs at the beginning of each chapter.
    I updated all numbering across the book files before generating the TOCs in the front matter, then generated the brief and detailed TOCs using my TOC Styles. However, I assigned cross references for the individual chapter TOCs. May not have been the best choice.
    Because there was special styling for some of the front matter TOC entries that wasn't easily specified using just the TOC Styles, I cut and pasted groups of entries from the generated TOC on the pasteboard into a new frame on the page. I checked in Story Editor to ensure that the invisible markers for the TOC entries had been copied into the new frame.
    When I exported the files to PDF, the TOC entries no longer pointed to the correct pages. They simply pointed to the first page of the PDF when clicked. Furthermore, no bookmarks showed up the TOC entries in the Bookmarks panel, even though I had "Create PDF Bookmarks" checked in my TOC Styles.
    I have three questions, then:
    --Is there any way to reclaim the behavior of the TOC bookmarks, and their display in the Bookmarks list of the PDF, if the entries are copied and pasted into a new frame in InDesign, without doing this manually in Acrobat Pro?
    --Is there any way to get cross references to display as bookmarks in a PDF, assuming that I needed to make individual PDFs of each chapter, without doing this manually in Acrobat Pro?
    --I'm betting that all files should be exported from InDesign as a single PDF in order for all TOC and cross reference links to work properly, without manual intervention in Acrobat Pro? If so, and manual intervention is required, is this accomplished by cataloging/indexing in Acrobat Pro?
    I need to be able to pass this information along to a publisher who is now requiring all of their compositors to submit bookmarked PDFs with their printer files. I'm pretty sure I know the answer to this one, but I would like verification from the pros here. Thanks!

  • Copy and paste ignores track text edit preview settings?

    Hi all,
    Working with FM9 and another editor that requires me to copy and paste from FM9 into the other.
    Enable and use tracking text edits in FM9.
    Preview Final to hide the edits.
    Copy and paste a paragraph that contains edits.
    When I paste into the target text editor, the "deleted" text is also displayed.
    Any way to prevent text hidden with a condition tag (which is how the tracking changes are marked) from being copied?
    -g

    I'm pretty sure the answer is no, not in FM itself. The only way would be to create a finalized FM doc with the changes accepted prior to copy / paste.
    It would be possible with a Framescript, though -- something like this:  the user copies the text,  hits a specified function key, the script pastes the text onto a special reference page, deletes the "deleted" text, recopies the text and then it beeps so that the user can then paste into the target editor.
    More info about Framescript at http://www.framescript.com and on the user group at
        http://groups.yahoo.com/group/framescript-users/

  • How can I copy and paste a pdf form onto my Mavericks Clipboard. I only see word-wrapped text.

    How can I copy and paste a pdf onto my Mavericks Clipboard. I only see word-wrapped text.

    Yes, Thank you for using the term Place. You moved my focus off the clipboard, and Place set me back on course. Somewhere, the terms Copy and Paste need to be tagged to Place and Export. I'm a database designer who only uses Illustrator for forms the database fills. My need isn't yet met, but the rest should come with reading the right references. Thanks Larry!

  • Is it possible to download a PDF of "ActionScript 3.0 Language and Components Reference"?

    I have found the "ActionScript 3.0 Language and Components Reference" online fine but my Internet is sometimes slow and I would like to take the reference with me even when I am not connected to the Internet. Is there a way to download a PDF version of this reference and if so, how? Help would be very much appreciated. Thanks

    The second item in the listing, ActionScript 3.0 Reference for the Adobe Flash Platform (ZIP, 66 MB) is a standalone copy of the files that you are looking for.
    Here's an Adobe Community file on how to implement the local help: http://forums.adobe.com/thread/1000134

  • How do i copy a cell reference to another tab in a sheet

    I need to copy a cell reference in another tab in a sheet, but do not know how..

    Connect the two computers by ethernet cable, LAN or Target Disk Mode, Transferring files between two computers using FireWire, and just drag the iPhoto Library package from Mac A to Mac B.

  • Cannot copy and paste to third party word processor.

    Greetings to all, I have Windows 7 Professional 64 bit with latest updates on a W520.This is my personal computer with no network. I can not copy and paste, to third party word processor. I was trying to copy and paste to an external hard drive. The computer knows the drive is there. When I do the response is that I have to contact the administrator. Thank you.

    Hi Ldxrunner2015
    I would like to know what word processor program are you using?
    Is your W520 managed by company (Domain) or personal?
    When the response is contact the administrator, does it prompt you for password or other credentials?
    Have a nice day! 
    Peter
    W520 (4284-A99)
    Does someone’s post help you? Give them kudos as a reward, as they will do better to improve | Mark it as solved if the solution works for you, so it could be reference for others in the future
    =====================================
    Sound Enthusiast and Enhancement (Post comments, share mixes, etc.)
    Dolby Home Theater v4 ; IdeaPad Slate Tablet

  • Copy and Paste Large (more than 999 rows) Spreadsheet

    I have a large spreadsheet that has a number of hidden columns.  It is about 1,135 rows long.  I have no trouble copying and pasting the spreadsheet into Pages (both are IWork '09) as long as I only try to copy and past 999 or fewer rows.  But when I try to copy and paste more than 999 rows, I only get the cell contents pasted into Pages.  The cell borders and formatting all get removed.  I have tried different groupings of 999 and always get the same results whether I am trying it will range 1-999 or 100-1099.  999 cells can be copied and pasted, but 1,000 or more get stripped of any formatting during the paste.  Any suggestions?  I've tried rebooting, running disk utility and renaming the Numbers document.  I've tried copying and pasting the contents of the numbers document into a new numbers document, but get the same results.  I've exported the Numbes document as an Excel document and reopened it using Numbers but still get the same results.  Anybody got any suggestions?  I'm running OS X 10.6.8 and everything is current.

    Hello
    To be complete on the subject, I tested the number of columns allowed by Pages in a table.
    The document format, portrait or landscape, doesn't matter. Pages accept only 65 columns.
    This limit may have a simple explanation :
    in Binary format, 64 is represented by 1000000
    and of course as we start from 0, 7 digits allow to define 65 values.
    For the 999 rows limit I have no idea. The binary representation of 998 is : 1111100110
    I would be surprised  that Apple use the decimal system to count the rows and if it does, the logical limit wasn't 999 but 1000 which is the count of integers from 0 thru 999.
    At this time the larger table which I use regularly is a Numbers one with 5296 rows in which I store the references to Apple Technotes. It receive about 20 new rows every week.
    I splitted the original 6942 rows one in two tables : the one with 'living' technotes and a 1646 rows one storing the now obsolete technotes.
    15 days ago, it was an AW6 database but I decided that it was time to to switch it in today's application.
    Yvan KOENIG (VALLAURIS, France)  07 /11 /2011 21:38:53
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2
    My iDisk is : <http://public.me.com/koenigyvan>
    Please : Search for questions similar to your own before submitting them to the community

  • How to copy and paste formulas between documents in numbers 3.0?

    I am unable to copy and paste formulas between 2 documents in numbers 3.0?

    Hi Hans,
    I can get a reference error here if the destination table does not have that range available while the source table does. 
    Are you sure your desination table has exactly the same structure and dimensions as your source table?
    If it does, copy/paste via the Formula Editor should work. It works reliably here.
    Also the formula in your latest post looks as if it might be corrupted-- lots of extra spaces (it seems).  Did your orginal formula have those?
    To sort this out, suggest turning off 'Use header names as labels' in Preferences.
    If you end up with a formula in a cell as just Text (as Ian describes that's what happens when you copy from Numbers 2) you can convert that text to a formula by double-clicking the cell, clicking just before the text so that the insertion point appears in front of it and typing =. That activates the Formula Editor with the formula in it, which you can accept by clicking the green checkmark or hitting return.
    SG

Maybe you are looking for