Object or Reference questions

class A
         A()
                  System.out.println("Inside A");
class OR
          public static void main(String args[])
                           A obj_a=new A();//This create an Object of class A
                           A ref_a;//This create a Reference of class AWhat are the differences between an Object and a Reference of a class?

new A() - creates the actual object.
Both obj_a and ref_a are references.
obj_a is referencing the object you created, and ref_a is not assigned yet.

Similar Messages

  • Interactive objects and quiz questions

    Hi everyone,
    I know that you can't add interactive objects to quiz questions, so what is the best way to accomplish my need of placing a button that, when clicked, plays a short mp3 audio file to a quiz question?
    Alternatively, if I am to replace my Captivate quiz questions with new custom slides, how can I replicate all of the multiple choice, etc question types? Are there widgets for these?
    I appreciate the help! I was looking around for reference items speaking to this issue but couldn't find any.

    Hello,
    On default question slides like on other slides, you can attach an audio clip to an object (even an object that is invisible to the user like a rectangle without a stroke and an fill with alpha=0%). The clip will play when the rectangle gets visible, but... you cannot put a button on a question slide. The only button that is possible is the static button widget but it has not the possibility to show/hide an object. You can attach the clip to the Success/Failure captions, eventually show/hide the invisible object with events like entering a slide, or Success/Failure actions but those events (appearing of captions, executing actions) cannot be controlled by a button.  If that is what you want, you need custom question slides. You didn't explain really at what moment you want to offer the audio, perhaps you do not need to give total control for playing by a button?
    Several blog posts I created talk about creating custom question slides with or without the help of widgets. Here is one link that shows a list of the articles/posts with widgets:
    Widgets and Custom Questions
    Not all question types are possible: if you want drag&drop functionalities I recommend the Drag&Drop widgets of InfoSemantics. Have a look here:
    http://www.infosemantics.com.au/dragdrop/whichwidget
    Another problem is the reporting of custom question slides. I already published two posts about that subject on my blog as well.
    Lilybiri

  • Passing objects by reference in PL/SQL

    Hi,
    I have come across an unexpected problem using object types in PL/SQL that is causing me some grief. I'm from a Java background and am relatively new to Oracle Objects but what I'm trying to do is fairly trivial, I think. The code below illustrates the problem.
    --- cut here ---
    CREATE OR REPLACE TYPE test_obj_t AS OBJECT
    num INTEGER,
    CONSTRUCTOR FUNCTION test_obj_t RETURN SELF AS RESULT
    CREATE OR REPLACE TYPE BODY test_obj_t IS
    CONSTRUCTOR FUNCTION test_obj_t RETURN SELF AS RESULT IS
    BEGIN
    num := 0;
    RETURN;
    END;
    END;
    CREATE OR REPLACE PACKAGE test_obj_ref AS
    PROCEDURE init(o IN test_obj_t);
    PROCEDURE inc;
    FUNCTION get_num RETURN INTEGER;
    END;
    CREATE OR REPLACE PACKAGE BODY test_obj_ref IS
    obj test_obj_t;
    PROCEDURE init(o IN test_obj_t) IS
    BEGIN
    obj := o;
    END;
    PROCEDURE inc IS
    BEGIN
    obj.num := obj.num + 1;
    END;
    FUNCTION get_num RETURN INTEGER IS
    BEGIN
    RETURN obj.num;
    END;
    END;
    --- cut here ---
    The object type test_obj_t holds a integer and the test_obj_ref package holds a 'reference' to an instance of the object.
    To test the above code I run this PL/SQL block:
    declare
    obj test_obj_t;
    begin
    obj := test_obj_t;
    test_obj_ref.init(obj);
    dbms_output.put_line('obj.num='||obj.num);
    dbms_output.put_line('test_obj_ref.get_num='||test_obj_ref.get_num);
    test_obj_ref.inc;
    dbms_output.put_line('obj.num='||obj.num);
    dbms_output.put_line('test_obj_ref.get_num='||test_obj_ref.get_num);
    test_obj_ref.inc;
    dbms_output.put_line('obj.num='||obj.num);
    dbms_output.put_line('test_obj_ref.get_num='||test_obj_ref.get_num);
    end;
    giving the output:
    obj.num=0
    test_obj_ref.get_num=0
    obj.num=0
    test_obj_ref.get_num=1
    obj.num=0
    test_obj_ref.get_num=2
    It appears that the object held by the test_obj_ref package is being incremented as expected, but I would have expected the object declared in the PL/SQL block to be pointing to the same object and so should report the same incremented values.
    I suspect that the object is copied in the call to test_obj_ref.init() so I end up with two object instances, one that is held by the test_obj_ref package and one in the anonymous block. Although, I thought that all IN parameters in PL/SQL are passed by reference and not copied!
    Am I right?
    Is passing objects by reference possible in PL/SQL, if so how?
    I'm using Oracle 10.2.0.3.
    Cheers,
    Andy.

    the object being passed to the test_obj_ref.init+ procedure is passed by reference; however, when you assign it to your package variable obj it is being copied to a new instance. you can pass object instances as parameters to procedures using the +IN OUT [NOCOPY]+ *calling mode, in which case modifications to the attributes of the passed object will be reflected in the calling scope's instance variable.
    oracle's only other notion of an object reference is the +"REF <object-type>"+ datatype, which holds a reference to an object instance stored in an object table or constructed by an object view.
    hope this helps...
    gerard

  • Multiple fill blank objects on one question slide?

    Hellou CP users, is it possible to put multiple fill blank objects on one question slide? And if, how can I manage them for quiz reporting and correct results?
    Yarik

    I think indeed that you want a score for each fill-in-the-blank object, and that is not possible with the default FIB question slides. Only MCQ has partial scoring.
    With TEB's and advanced actions that is possible. Also with the TextArea widget, as I explained in this blog post:
    http://blog.lilybiri.com/widgets-and-custom-questions-part-2
    http://blog.lilybiri.com/extended-textarea-widget-more-functionality
    TEB's have the advantage that as interactive objects, you can attach a score to them which is not the case for the TextArea widgets. But I would recommend getting Jim Leichliter's enhanced version of the TEB's as well, so that you can control what is shown in the TEB if you want to create a question with multiple attempts. I have described a use case recently in these forums but cannot remember exactly which thread. Jim's widget is free:
    http://captivatedev.com/2012/09/16/adobe-captivate-6-x-free-widget-text-entry-box-with-var iables/

  • Does Java pass objects by Reference

    The following is my code:
    public static boolean isValid(String tester, Integer intHours, Integer intMinutes)
              int dotPosition = tester.indexOf('.');
              String hours = tester.substring(0, dotPosition);
              String minutes = tester.substring(dotPosition +1, tester.length());
              try {
                        intHours = Integer.valueOf(hours);
                        intMinutes = Integer.valueOf(minutes);
         } catch (NumberFormatException nfe) {
         return false;
         return true;
    What Iam trying to do is pass the Integer Objects by reference so that they retain their values outside of the scope of the function. My teacher told me that objects are passed by reference in Java but (even though the values are being changed within the function they are not retaining their values outside the scope of the function. Was my teacher wrong?

    aden_jones wrote:
    So to get behaviour similar to passing by reference I would need to create my own object and give it a method e.g. MyObject.changeValue(new_value) but I can't do that with Integer objects because I can't change their actual value I can only change the Integer Object that is being pointed at??You cannot achieve behavior that duplicates PBR with Java.
    However, if by "similar to passing by reference" you mean that the method makes a change that the caller can see, then, yes, you need to pass a reference to a mutable object, and change that object's state inside the method.
    void foo(Bar bar) {
      bar.setBaz(123);
    Bar bar = new Bar();
    bar.setBaz(999);
    foo(bar);
    // after foo() completes, the caller now sees that the Bar object's internal state has changed
    // from 999 to 123Note the difference between changing the value of a caller's variable (which can be done with PBR, and cannot be done in Java) and changing the state of the single object pointed to by both the caller's variable and the method's copy of that variable (which can be accomplished in Java, as it does not rely on PBR).

  • ORA-22806 : not an object or reference in 10gRel2

    Hi,
    We have recently successfully upgraded our oracle 8i database to 10.2.0.1
    database is up and running fine, but
    one of the user created procedure is giving error as below :
    ORA-22806 : not an object or reference
    See the below code :
    =============
    v_cnt:=0;
    Check_Str := 'SELECT COUNT(*) FROM P_EMP_HOLIDAY_DATE
    WHERE company_id=:p_Comp_id
    AND branch_id = :rec_branch.branch_id
    AND employee_id =:rec_emp.employee_id
    AND :v_nxt_date IN holiday_date';
    EXECUTE IMMEDIATE Check_Str INTO v_cnt USING p_Comp_id,rec_emp.branch_id, rec_emp.employee_id,v_nxt_date;
    Put_Any_Line('v_cnt : ' || v_cnt);
    when we run the procedure it gives the error at line 186 .i.e the line with EXECUTE IMMEDIATE statement in above
    so where is the problem ?
    this procedure was running fine without any problem in our oracle 8.1.7.0 version now showing error in 10.2.0.1
    is there any syntax problem that is not being suported in the upgraded version i.e. 10.2.0.1
    how to get it solved ?
    As this is very urgent to solve so any immediate support would be appreciated.
    with regards

    What is Put_Any_Line ? Why are you using dynamic sql here ?
    As this is very urgent to solve so any immediate support would be appreciated.Ok, then please, do not hesitate to use the Oracle support, and see how it can be immediate support.
    Nicolas.

  • Service Object Init References

    Has anyone come up with a good work around to allow Service Objects to
    reference other service objects in their init methods or during application
    startup. Since we can't specify the order in which Service Objects start,
    is there a way we can execute some code once all Service Objects have come
    online?
    Will this idea work?
    Start a task in the init method that loops for the referenced service object
    to not be nil, then references the needed SO. For example:
    while true do
    if LogMgrSO = Nil then
    task.delay(100);
    else
    exit;
    end if;
    end while;
    Eric Rasmussen
    Project Manager
    Online Resources & Communications Corporation
    (703)394-5128
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

    Hi,
    Sorry to answer so late ! I left (one year ago may be) some Tool code on
    the Mailing list on that subject.
    May be you have to consider some different cases :
    1&deg;) Is a Service started because it is only instanciated (<> NIL)?
    2&deg;) Forte insures that the first services to be started on a partition
    are DBsession and DBResource Managers.
    3&deg;) A local Service or a distributed service are not exactly treated the
    same way.
    4&deg;) The init() method has a specific way to run : the allocations are
    made at the end.
    1&deg;) When a Service is not NIL it is only that it is instanciated. So
    your initialization sequence is not endded may be or
    the service is not insured to be started properly. It should be
    important if you need to load a cache for instance. I
    would recommand to test that a service is ON (for DBsessions for
    instance) and to add (if possible) a state to determine
    that a service is properly started.
    2&deg;) This is only available if you are inside the same partition on the
    same machine. So if you have to synchronize with
    external ressources from the partition you will need to treat them like
    other services.
    3&deg;) A local Service will be NIL and then instanciated. The classname
    will be the same as in the workshop.
    A distrubuted service (exactly a service which is not on the same
    partition) will have a different classname (Classname+Proxy).
    So the external service proxy may be instanciated but the So May not,
    and you will get a DistributedAccessException.
    4&deg;) The init() method may not be the best location for a synchronization
    if you need to use an array for instance to
    store you dependencies. So I would use a start task on an InitService()
    method to avoid that problem.
    Options :
    - A dependency could be optionnal : after a certain amount of tries you
    can abort synchronization on the service.
    - You can use synchronization on "cold" and "hot" startup of services.
    - You can develop a service agent which cold have instruments to see
    dependencies and states, and commands to stop/start services.
    - The Delay you may play should be different for each service you are
    waiting for.
    - The order of dependencies should have an importance (first put
    mandatory dependancies, and then optional ones).
    - A Service is not only a Service Object, but could also be just a
    reference to an instance through a container for example.
    - Some kind of autoStart : should I start all my services at the
    beginning of my application or could I start some services
    at the first call ? This should be available if you use your own
    application protocole and if your services are inside some
    service managers for instance.
    Remarks :
    Thoses concepts have been tested on a Framework from R2 to R3 of Forte
    with success. With those, you can imagine
    starting the application without knowing if the database is running, the
    application will wait for the database
    to be mounted. An other advantage of the synchronization is that you
    will resolve the naming of the services at
    the begining of the application. Then, you can stop the environment
    manager and the application will still work
    (for the clients which were already started of course). You can also
    imagine transfering your partitions from one
    node to an other at run-time.
    Hope this helps,
    Daniel Nguyen
    Freelance Forte Consultant
    Stephen McHenry wrote:
    >
    At 11:04 AM 10/1/98 -0700, John Jamison wrote:
    begin
    while true do
    begin
    ..attempt "remote" SO reference..
    exit; // while true do loop
    exception
    when e:UsageException do // if in same partition and not yet
    initialized,
    // you get a NIL object exception
    task.errormgr.clear;
    when e:DistributedAccessException do (or RemoteAccessException)
    // if in a different partition, get this
    error
    task.errormgr.clear;
    end;
    event loop
    aTimer : Timer = new (tickInterval=5*1000); // 5 seconds -
    adjust to taste
    aTimer.isActive=true;
    when aTimer.Tick do
    aTimer.IsActive=false;
    exit;
    end event;
    end while;
    end;One of the problems I see with all of these "catch the exception and try
    again" schemes is that they fail to take into account that the SO you are
    calling may, in fact, never appear (due to some sort of problem, of course)
    and then you never exit this loop. It's a "liveness" problem with this
    approach. So, be sure to add some alternate way out after 1 minute (or
    whatever your particular threshold is) and raise an exception yourself.
    Always gotta think about what happens if something goes wrong... ;-)
    Stephen
    |===========================================================================
    ===|
    |Stephen McHenry | Design Consulting |Training courses
    offered: |
    |Advanced Software Tech | | -Distributed
    Obj-Oriented |
    |305 Vineyard Town Ctr #251| [email protected] | Analysis &
    Design |
    |Morgan Hill, CA 95037 | (408) 776-2720 x210 | -Intro to Object
    Technology|
    |USA | http://www.softi.com | -Advanced OO Design
    |
    |===========================================================================
    ===|
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>-
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

  • Application Object Library Reference Manual in EBS 11.5.9 Docs

    Hi,
    I have bumped to a reference of the book "Application Object Library Reference Manual". Since this reference is about an old EBS version(10.6) and i want the equivalent of this for the EBS 11.5.9. , can you please write which one is this from url:
    http://download.oracle.com/docs/cd/B12190_11/current/html/docset.html
    Many thanks,
    Sim

    Hi,
    Actually , i have read on some docs located at :
    http://www.bryanthompsononline.com/oracle/2008/05/06/download-oracle-aim-applications-implementation-methodology-software/
    about the above reffered Oracle EBS document. I have searched on the typical Oracle EBS 11.5.9. doc , but i've not found this exactly doc (with this title). So , i have asked if anybody could point me to the relative doc on EBS 11.5.9. docs set......
    Many thanks for the link anyway.....
    Greetings,
    Sim

  • Moving object instead references

    I want to copy an object into a matrix, and then equal that object to zero. But it something goes wrong, I suspect this is because only a reference is copied into the matrix, and not the object itself. And when I remove the object, the reference is obsolete. Is there a way to avoid this? I tried implenting the Cloneable interface in the object, and then putting a clone in the matrix, but it still doesn't work. Thanks

    Your conception seems like C program. Be careful to do Object programmation.
    In Java, remember that you have only references (equivalent to pointers in C).
    In java you manipulate only the references through the variables.
    An object is never set to null, only the variables which contains references to this object. The object is still here but not reachable.
    Look this code :
    MyObject var1 = new MyObject();
    MyObject var2 = var1;
    var1 = null;
    Now let see how the program works :
    new MyObject() create an instance of the class MyObject and store it at the adress 2000 (for example).
    MyObject var1 = new MyObject();
    In the created variable var1, the adress of the newly created object will be stored. var1 <-- 2000
    MyObject var2 = var1;
    We create a new variable var2 in which we store the value of the variable var1 i.e. : 2000 : var2 <-- 2000
    var1 = null;
    In the variable var1 the value is set to null : var1 <-- null.
    At this moment the variable var1 contains no reference (null) and var2 still contains 2000 the adress of the object in memory.
    I hope it is clearer for you,
    Denis

  • Rotate object by Reference Point?

    I did a search on the forum on how to rotate an object by % using one of the object's reference points but came up empty.
    It seems like something I've overlooked. I'm sure there's data on it, but I can't find it. Can anyone show me how to do this.
    Thanks

    app.layoutWindows[0].transformReferencePoint = AnchorPoint.topLeftAnchor;
    myObject.rotationAngle = 30;
    Peter

  • Object casting: confusion in ABAP Objects: Complete Reference book

    Hi,
    During Object Assignments using casting, is a Type Test carried out during the syntax check or at runtime?
    A.5.2.2 (page 1008) of 'ABAP Objects: The Complete Reference' says about Widening Cast: "...you must check at runtime...". However on the next page under A.5.3.2 it says of Widening Cast in Data References: "The syntax check precludes...".
    A.5.4 (page 1010) concerns Assignments between Object Reference Variables, but makes no mention of whether checks are carried out by a syntax check or at runtime.
    Also nowhere does it mention when Type Tests for Narrow casting takes place. Can anyone clear my confusion please? Unfortunatly I don't know enough about this stuff to test by writing some code.
    Thanks.

    William,
    Your questions can be answered by the following rule for object references, which I found in the book "ABAP Objects" by Horst Keller and Sascha Krüger:
    "... that the static type of the target variable must be equal to or more general than the dynamic type of the source variable."
    Here "static type" means the type with which an object reference variable is declared. "Dynamic type" is the type that the object reference variable has at runtime. The dynamic type of an object reference is always more special than its static type, otherwise a runtime error occurs.
    With this rule all your questions can be answered:
    1. The Narrowing Cast is always checked during the syntax check. Example:
    DATA o_ref1 TYPE REF TO object.
    DATA o_ref2 TYPE REF TO class_1.
    o_ref1 = o_ref2.  
    Here the reference o_ref2 has a dynamic type "class_1" or a subclass of it, which is narrower than its static type "class_1", which is narrower than the static type "object" of the reference o_ref1. Therefore, the syntax check says that the assignment is OK.
    2. The Widening Cast is always checked at runtime and requires an assignment using the operator ?=. If you use the operator = in the assignment, a syntax error occurs. Therefore the following  example produces a syntax error (try it yourself):
    DATA o_ref1 TYPE REF TO object.
    DATA o_ref2 TYPE REF TO class_1.
    o_ref2 = o_ref1.  
    The correction for this syntax error is:
    DATA o_ref1 TYPE REF TO object.
    DATA o_ref2 TYPE REF TO class_1.
    o_ref2 ?= o_ref1.
    Now the syntax check is satified, and the correctness of the widening cast is checked at runtime.
    Kind regards,
    Michael Kraemer
    Message was edited by: Michael Kraemer

  • Object as Reference not working..Please help..!!!

    public class GG{
    public static void main(String[] args) {
    Integer i = new Integer(10);
    System.out.println("Before Call:"+i);
    change(i);
    System.out.println("After Call:"+i);
    public static void change(Integer x){
    x=20;
    Here the output is coming
    Before Call:10
    After Call:10
    I am confused when i am passing an object in a function then why the value is not changed as objects are passed by reference??

    Java is pass-by-value. Recommended reading:
    [http://www.javaranch.com/campfire/StoryCups.jsp]
    [http://www.javaranch.com/campfire/StoryPassBy.jsp]
    This topic has been done to death too many times already. I'm moving this thread to New to Java and locking this it. Jasvinder.Singh, please confine your questions to the New to Java forum until such time as you can regard yourself as a Java Programmer.
    db

  • Object and reference accessing for primitives, objects and collections

    Hi,
    I have questions re objects, primitives and collection accessing and references
    I made a simple class
    public class SampleClass {
         private String attribute = "default";
         public SampleClass()
         public SampleClass(SampleClass psampleClass)
              this.setAttribute(psampleClass.getAttribute());
              if (this.getAttribute() == psampleClass.getAttribute())
                   System.out.println("INSIDE CONSTRUCTOR : same object");
              if (this.getAttribute().equals(psampleClass.getAttribute()))
                   System.out.println("INSIDE CONSTRUCTOR : equal values");
         public void setAttribute(String pattribute)
              this.attribute = pattribute;
              if (this.attribute == pattribute)
                   System.out.println("INSIDE SETTER : same object");
              if (this.attribute.equals(pattribute))
                   System.out.println("INSIDE SETTER : equal values");
         public String getAttribute()
              return this.attribute;
         public static void main(String[] args) {
    ...and another...
    public class SampleClassUser {
         public static void main(String[] args) {
              SampleClass sc1 = new SampleClass();
              String test = "test";
              sc1.setAttribute(new String(test));
              if (sc1.getAttribute() == test)
                   System.out.println("SampleClassUser MAIN : same object");
              if (sc1.getAttribute().equals(test))
                   System.out.println("SampleClassUser MAIN : equal values");
              SampleClass sc2 = new SampleClass(sc1);
              sc1.setAttribute("test");
              if (sc2.getAttribute() == sc1.getAttribute())
                   System.out.println("sc1 and sc2 : same object");
              if (sc2.getAttribute().equals(sc1.getAttribute()))
                   System.out.println("sc1 and sc2 : equal values");
    }the second class uses the first class. running the second class outputs the following...
    INSIDE SETTER : same object
    INSIDE SETTER : equal values
    SampleClassUser MAIN : equal values
    INSIDE SETTER : same object
    INSIDE SETTER : equal values
    INSIDE CONSTRUCTOR : same object
    INSIDE CONSTRUCTOR : equal values
    INSIDE SETTER : same object
    INSIDE SETTER : equal values
    sc1 and sc2 : equal values
    ...i'm just curios why the last 3 lines are the way they are.
    INSIDE SETTER : same object
    INSIDE SETTER : equal values
    sc1 and sc2 : equal values
    how come while inside the setter method, the objects are the same object, and after leaving the setter method are not the same objects?
    Can anyone point a good book that shows in detail how objects, primitives and collections are referenced, especially when passed to methods. Online reference is preferred since the availability of books can be a problem for me.
    Thanks very much

    You are confusing references with objects.
    This compares two object references:
    if( obj1 == obj2 ) { // ...Whereas this compares two objects:
    if( obj1.equals(obj2) ) { // ...A reference is a special value which indicates where in memory two objects happen to be. If you create two strings with the same value they won't be in the same place in memory:
    String s1 = new String("MATCHING");
    String s2 = new String("MATCHING");
    System.out.println( s1 == s2 ); // false.But they do match:
    System.out.println( s1.equals(s2) ); // trueIf you're using a primitive then you're comparing the value that you're interested in. E.g.
    int x = 42;
    int y = 42;
    System.out.println(x == y); // trueBut if you're comparing references you're usually more interested in the objects that they represent that the references themselves.
    Does that clarify matters?
    Dave.

  • Help - Concept: Object and reference?

    Q1:
    In Java tutorial, it says: The real-world objects share two characteristics: They all have state and behavior.
    State is associate with variables. So I am wondering where the object reference fit in the object if an object encapsulates some children objects? Is reference also varaibles?
    For example, if a MailInBox object has the size property, numberOfMessage property and a reference to each message object, does this mean that MailInBox object has property of size, numberOfMessage and all references?
    If reference belong to an object, an object can own both attribute properties and object references, right?
    =================
    Q2:
    What is the clientship of an object?, please help give me an example.
    Thanks!

    Thanks for your reply.
    For first question, My original question was whether an object can have both attribute properties and object references.
    Here if a MainBox object has 1) a simple attribute "size" which is integer type, so "size" is the attribute of the MainBox; 2) At the same time, if a MainBox has a child object called "Inbox", so a MainBox object has a reference to the Inbox.
    So in this sense, I concluded that an object can have both attribute properties (here is "size") and object references (here is "size"). Is it right?
    This can also be inferred from your statements:
    It is correct to assume that an object has attributes, which
    simplistically reflect its state.Then,
    Therefore, the Mail Box object only has 2 references.But In Java tutorial, it says: The real-world objects share two characteristics: They all have state and behavior.
    Then I concluded that Both reference and attributes are variables, right?
    =====
    So is it safe to say, "an object can have attribute and reference"?
    or
    is it safe to say, "an object can have attribute with reference"?
    Thanks!

  • Copying value of objects, not reference?

    This has been bothering me for a while. I learned that when you set one object equal to another you are really just assigning the same reference to both, so that if one is altered they are both altered. Well, how can you set one object equal to the value of another but not the same reference so that altering one will not alter the other. My concern stems from returning arrays in methods. Since the reference itself is passed, any changes I make to the array are permanent, correct, and not just existing inside the method? So I was thinking maybe the best solution would be to use a tmp{] variable that is equal to the VALUE of the array I pass in, and then return that, so the original array is not altered in any way. Is this the customary practice for dealing with such situations? If not, what is typically done? Oh and just for future reference, because it might be of value to know, how DO I copy a value and not a reference? (and yes, that WAS on purpose ;) )

    violagirl23 wrote:
    My concern stems from passing arrays to [KRC] methods. Since the reference itself is passed, any changes I make to the array are permanent, correct, and not just existing inside the method? So I was thinking maybe the best solution would be to use a tmp{] variable that is equal to the VALUE of the array.Both georgemc and tschodt have already given you some good pointers, I'll try not to reiterate the same advise.
    This is an old "problem", discussed at length by folks much smarter than myself, and (IMHO) there still is no definitive question, let alone universal answer. What I mean is that sometimes this ability to modify the contents of a collection or array within a method is highly desirable; and sometimes of course it's just a source of bugs, when a noob calls your method not realising that it modifies the contents of the passed array (which shouldn't make it past unit testing anyway)... So, I think probably the best thing I can do for you is to give you the terms to google.
    What you're talking about is called a defensive copy... which, especially with arrays and collections, typically involves a deep copy (make a copy of every attribute of every object, all the way down the reference tree)... as apposed to Arrays.copyOf, which is a shallow copy, i.e. it just copies the references to the "top" objects.
    If you're writing a system from scratch you could decide to implement clone methods for everything you ever need to defensive copy. Cloning is ugly, no matter how you cook it. It requires every part of the class heirarchy being cloned to support the clone method (properly).
    In the past, I've tried to write a "generic" copy method, in the abstract-base-type of a class heirarchy using reflections. Everything I've tried has "pretty fatal" flaws. The only "proper" solution (AFAIK) is to just implement clone in every single frickin class... and that's a lot more "boiler plate" code than I personally think should be required to implement such a common, mundane task.
    Alternately, you could make all your data transfer objects immutable, so a shallow copy (Arrays.copyOf) of the array is enough to protect the calling code from unexpected changes to the array contents because you are passing "a copy" of the references to things-that-cannot-change... So the callee cannot mutate a pointed-to object, and if the callee changes which object an array element points-to, you won't "see" the change... and of course the callee cannot change which array your reference points to, because Java passes references by value.
    Google all the italic stuff... Sun's stuff is the best, then lookout for IBM's stuff, and most Wikipedia articles are really good (a few not so good).
    HTH. Cheers. Keith.

Maybe you are looking for

  • Please help - AbstractTableModel, result set and JTable

    Pls help me on this: I derive a new class, myTable that extends the AbstractTableModel, one of the member method is like this: public void setValueAt( Object data, int row, int col ){ try{ resultSet.absolute( row + 1 ); resultSet.updateDouble( col +

  • Want to Move to QT streaming

    I am working on a video streaming project for my church. We are having problems with windows and our video mixer. We have a few Mac Pro's that were previously used for our recording studio that are not being used for the foreseeable future. We would

  • Chart Comb with  Static Table.

    Hello everyone! I have a graph made of bars and one static table below (with a column sorting). I need that the graph actualize automatically when I click on the table to see the next 10 items in the column sorting button. Thank you for your help! Ed

  • Connect Same BO server to Two BI system QBW and DBW

    Hello friends we are using same BO server to connect to two BI system DBMW and QBMW. we are not able to see the OLAP Cubes during the creation of universe connection using the Quality system QBMW and Application server "sapbmw01" client 100, system #

  • Question on the Gapless Play feature

    I'm setting up my new 80gb and was curious if there was anyway to get iTunes to go through my libray and set up the gapless play. Right now I have to go through each album's and click that it is part of a gapless album. Any idea on if this can be don