Reference type clarification

I was studying the training CD from Sun Java and at one point it says that a variable of type of a certain object keeps the value of the allocated memory for the object rather than the object itself. So far so good
So if the we have the following:
MyDate my_birth = new MyDate(22, 7, 1964);
MyDate anotherDate = my_birth;
However when we create a second variable of the type MyDate and copy my_birth into it what we have done is copied the value of the allocated memory
my_birth memory 0x12345678
anotherDate memory 0x12345678
but we have one object in memory and not too.
So this to me means that when I alter the object of anotherDate then my_birth object has changed since it's the same object.
But when I use
anotherDate = anotherDate.addDays(3);
System.out.println(my_birth);
System.out.println(anotherDate)
I have another date printing out on anotherDate and the initial date on my_birth. Wasn't my_birth supposed to be the same as anotherDate?

This line:
anotherDate = anotherDate.addDays(3);is making anotherDate reference a new instance (if that is what addDays returns), so anotherDate and my_birth are no longer referencing the same instance.
Kaj

Similar Messages

  • I need clarification regarding REFERENCE TYPES and CASTING.

    Hello all,
    I'm taking a course on the fundamental of JAVA. Everything's been going smoothly until I slammed into the the concept of CASTING and REFERENCE TYPES. Flat--out == I DON'T GET IT?
    I'm having trouble with...
    CONVERTING REFERENCE TYPES
    CASTING BETWEEN REFERENCE TYPES
    WORKING WITH REFERENCE TYPES
    I understand what's happening from an academic vantage point. I just don't understand why you'd want to convert REFERENCE TYPES? What would be an application of such an exercise?
    1. What IS a REFERENCE TYPE -- exactly?
    a. what are we referencing?
    b. type? type of what??
    for example... why would you want to do a widening conversion, a conversion of the hierarchy tree?
    I understand the concept of OBJECTS, CLASSES, METHODS and CONSTRUCTORS so far...
    I think it's the terminology that's screwing my up.
    Thanks,
    Alex

    ok... wow, thanks J.
    So--in a nutshell-- we're making it so that different
    objects:
    ie,. ford(), chevy(), honda(), lotus() and
    dealers()... so and so forth()...
    all share the resources(for lack of a better word) of
    the Auto Class? because all of those auto brand
    objects and one redically different object can be
    unrelated, correct?Um, yes and no.
    I just ran with the example you had, but that probably included too many concepts and they got muddied up.
    Yes, Chevy, Ford etc. all share the characteristics of Auto, since they're all subclasses. But that's just inheritance, and has nothing to do with casting.
    A "reference type" can loosely be described as a variable that refers to an object. (Constrasted with "primitive types" which are int, char, float, etc. and don't refer to objects--they just hold values.)
    Casting just tells the compiler that even though as far as it knows you only have a reference to some superclass, the object that reference points to will in fact be an instance of a subclass, and so treat it as such (e.g., we can now call methods that the subclass has that the superclass lacks).
    (You can also cast primitives, but one thing at a time.)
    So let's say you have class A (which extends object) and B extends A.
    A a = new B();
    B b = a; // won't compile. compiler sees the "A a" on the left of the =, not "new B()" on the right.
    B b = (B)a; // works because we're telling the compiler, "Dude, I'm seriously. This is a B.
    Note that if we had done new A() instead of new B(), it would still compile--the compiler would trust us. But at runtime, we'd get a ClassCastException, since we wouldn't actually have a B object.
    /**folks, I'm a web designer that has to learn Java
    so that I can perform my duties as a JSP author here
    at work. I tried to learn JSP sans Java and that was
    a simple exercise in ignorance.-- it's really hard
    without understanding the root concepts of Java and
    for that matter, C. Concepts like "polymorphism,
    inheritance, object references... are completely
    foreign to me. **/It's a rather big leap from web designing to OO concepts. Take your time, and don't be discouraged if you feel completely confused. It's a prerequisite. :-)

  • Diff b/w reference type and elementary type

    hi all
    can any one what is the diff b/w reference type and elementary type in data element ....
    thanks
    lokesh

    The data type attributes of a data element can be defined by:
    Specifying a domain whose attributes are copied by the data element.
    Specifying a build-in type where the data type, number of places, and possibly decimal places can be directly specified.
    Specifying a reference type, i.e. reference to a class, an interface, a type defined in the Dictionary, a built-in type, or a generic reference to ANY or DATA.
    In the maintenance screen you can set the option you require by setting the appropriate flag (domain, built-in type, reference type) and filling in the corresponding input fields.
    A reference type is a reference to another type. There are the following kinds of reference types:
    Reference to a class or an interface
    Reference to a type defined in the Dictionary
    Generic reference to ANY, OBJECT, or DATA
    Reference to a built-in Dictionary type with specification of the length and possibly also the decimal places
    You can use a reference type to define the data type properties for a data element, or for typing the component of a structure or the line type of a table type.
    In the field Referenced type, enter the name of a class, an interface, the generic references DATA, OBJECT, ANY, or the name of a type defined in the Dictionary. If the reference type is to be a predefined Dictionary type, choose the reference to the predefined type. Enter the number of characters and, if required, the number of decimal places.
    where as
    The data class describes the data format at the user interface.
    If a table field or structure field or a data element is used in an ABAP program, the data class is converted to a format used by the ABAP processor. When a table is created in the database, the data class of a table field is converted to a corresponding data format of the database system used.
    You can find a detailed description of the data classes allowed in the ABAP Dictionary in Overview of the Data Classes.

  • Error in sales order when selecting a warranty item in configurator 'Please enter required information - Service Reference Type Code'

    Error in sales order when selecting a warranty item in configurator 'Please enter required information - Service Reference Type Code'
    Not able to book the sales order because of this issue

    Order Management does not support the inclusion of optional service items in a configured Model BOM (see Support article #1296751.1 for more detail).  Allowing for such would therefore require customization.
    As you've found, there's no modeling restriction that prevents you from creating a Model BOM that includes optional service items, nor is there any problem with creating a Configurator Model for it.  And required service items (such as a warranty item that is a required child of an optional BOM component) do not present a problem; they have nothing to do with Configurator, and would never appear as sub-lines in OM.  The problem arises in OM, which requires that any service item be "associated" to the item it's "servicing".  OM does not automatically make such an association with service sub-lines, even though it might be argued that an association may be inferred by the BOM structure (i.e., OM does not assume that an optional service sub-line is necessarily associated, from a service standpoint, with its BOM parent).  OM customization is therefore required in order to hook any service item up to its corresponding product item.  Many customers who configure service along with product have implemented such a customization.
    (Another gap in such a solution that may be relevant to you is that for an included optional service item requiring recurring billing, Order Management does not create the requisite Service Contract.  Customers have likewise developed customizations to address this, as well.)
    As this is not specifically a Configurator matter (you could have created your order without using Configurator at all, and you would have experienced the exact same behavior), please do not take my explanation as being either authoritative or comprehensive (I am a Configurator expert, and only knowledgeable enough about Order Management to be dangerous).  It would be advisable for you to seek more detailed information/recommendations from the Order Management forum.
    Eogan

  • VI Reference type does not match VI connector pane

    I am trying to use Open VI Reference in LabVIEW 8.  I am getting error 1031 "VI Reference type does not match VI connector pane."  I have a Type Specifier wired to the Type Sepcifier terminal, and I've gone in and selected Select VI Server Class / Browse, and selected the VIT that matches the input path. 
    My path is correct.
    I wired 0x10 (16) to the options terminal so that I would be prompted if LabVIEW couldn't find the necessary subVI files.
    I restarted my computer to make sure the old type specifer was not in memory.
    Any thoughts on why I still get error 1031?
    Thanks,
    Kathy

    Hi Kathy,
    I am still investigating this problem, but right now I do have a workaround for you.  If you open your template VI and drag its icon into the type specifier constant, and also drag it into the refnum indicator on the panel of your calling VI, the problem no longer occurs.  For some reason the "Browse" operation is behaving differently than dragging the VI icon.  I will continue investigating this and let you know what I find out.
    Ben:  There is no way to automatically update the type specifiers.  I've seen people typedef their specifiers before, so they only have to change them in one place when the subVI connector pane changes.  We already have this suggestion on file to consider for a future LabVIEW version.
    -D
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman

  • Problem with Type Reference "TYPE' in JCO

    Hi All,
    I am facing a weard situation when i am creating a custom RFC function module. This FM is called by Java program with JCO. But, if i define the FM parameters with Reference type as 'TYPE', the Java application is not able to get the data. But the same time, if i declare the parameters with 'LIKE', it is working successfully.
    Can anybody advise me, why it is behaving differently? Is the problem with JCO which is not able to recognise the 'TYPE' reference or from SAP side?
    And, any solution to use 'TYPE' reference successfully?

    hi Sailesh,
    You are right. SAP doesn't recommend the usage of Like in PROGRAMS/REPORTS - mind it, only REPORTS.
    But when it comes to RFC enabled FMs, JCo Understands only LIKE. what you had observed is true. LIKE creates a WA and JCo looks into a workarea. TYPE can refer to a pool of variables but your JCo can't differentiate them. So, you use LIKE.
    Again, you use LIKE only Remote enabled FMs not in Reports/Programs. so, you may use TYPE as your company remommends in reports but in RFMs, use LIKE.
    Hope this cleared.
    Regards
    Ak.
    PS: If my post helped, don't forget the rewards!

  • Mission Control: Trying to find my class in Memleak in Reference Type

    Hi
    I'm trying to create some demonstrations of Mission Control and I want to create an example where I have a memory leak and I want to get to my class using reference type.
    This is my code:
    public class ThunderBombCracker {
    public ThunderBombCracker() {
    public void boom() {
    for (int index = 0; index < 10; index++) {
    new Thread("ThunderBombCracker " + index) {
    public void run() {
    List<ClientTo> lista = new ArrayList<ClientTo>();
    try {
    Random random = new Random();
    for (int index1 = 0; index1 < 120000; index1++) {
    byte[] buffer = new byte[16];
    for (int index2 = 0; index2 < 16; index2++) {
    buffer[index2] = (byte) (65 + random.nextInt(32));
    lista.add(new ClienteTo(new String(buffer)));
    sleep(1);
    sleep(120000);
    lista.size();
    } catch (Throwable e) {
    e.printStackTrace();
    }.start();
    public static void main(String[] args) {
    ThunderBombCracker boom = new ThunderBombCracker();
    boom.boom();
    Basically I create a lot of 16 character Strings and pass them to my own class ClientTo and wait for 1 minute. Now, when I run memleak I can see a lot of char[], a lot of Strings, a lot of ClientTo. But if I try to check the reference types of String it won't show ClientTo. Maybe I'm missing something here about how JRockit or Memleak works.
    Regards,
    Néstor Boscán

    Yes that is what I'm doing with the code. I'm creating Strings that are assigned to a ClientTo object and then added to a list. But I cannot see that the MemLeak shows me the reference between ClientTo and String.
    Regards,
    Néstor Boscán

  • How to use Reference type of Data Element

    Hi guys, is there anyone could give me a trace how to use reference type of data element.
    More details i'm going to reach is:
    I create 2 tables:
    eq.
    1. table ZFIRST has field X with data element ZFX (Data element i declared).
    2. table ZSECOND has field Y.
    Here at field Y (second table) I'm going to declare a new data element say it ZFY, but in ZFY I'm going to use the data element as i declared before (ZFX). Is it possible if I do it using reference type data element (SE11)?
    I already did this way, but I got error :
    Field Y: Reference ZFX to class w/o interface cannot be used in DB table ZSECOND
    What does it mean?. Did I miss something about using reference data element type?.
    This error occurs when I activate ZSECOND table. However in creating ZFY (reference) to data element ZFX, there is no error occur.
    The point is I need to RE-declared existing data element and ot put existing data element(ZFX) to my current table (ZSECOND).
    Any helpful will be highly appreciated.
    Thanks.
    Edited by: dinivian dondi on Nov 4, 2010 8:30 AM

    Field Y: Reference ZFX to class w/o interface cannot be used in DB table ZSECOND
    What does it mean?. Did I miss something about using reference data element type?.
    Apparently system doesn't allow you to type a transparent table field with deep type. This refers to references and tables types as components. The RDBMS (Relational DB Management System) cannot interpret this componenets correclty and mapp them to TABLEs in DB.
    So I am affraid you won't be able to type table component with reference to other data element.
    The point is I need to RE-declared existing data element and ot put existing data element(ZFX) to my current table (ZSECOND).
    Sorry but I don't get it, could you please explain this more clearly. Maybe then we can think of some workaround for you.
    Regards
    Marcin

  • How can a Collection of Primitive type be a Reference Type ?

    Here's the example that i am running:
    public class one
         public static void main(String args[])
              int i[] = new int[]{0,1,2,3,4,5};
              int j[] = i;
              j[0]=100;
              System.out.println(i[0]);
    }Output:100
    So the question is quite a weird one actually which i haven't seen any book explain...
    How can a group of int be a reference type ??
    please explain.

    i and j are both references. They point to objects. In this case, they point to the same object--an array of int.
    The fact that the contained elemets are primitives doesn't change the fact that the container is an object. It's just like if you did
    class Foo {
      int i1;
      int i2;
      int i3;
    }A Foo object is still an object, even though its member variables are all primitives, and Foo foo; is still a reference variable that points to a Foo object, just as i and j are reference variables that point to array objects.

  • How to control a reference type of BAM Relation to see Related Activites on BAM Portal?

    Hi.
    There is
    description of predefined reference types of BAM relations.
    I have created relation between two activities by adding Relationship node to one of them (to an activity that is tracking detailed orchestration). Both activity are declared in one definition file. I put InterchangeId field to Relationship
    node and  it is working. (InterchangeId also is used as ActivityId in "master" activity), I see in CompletedRelationships table the record
    ActivityID
    ReferenceName
    ReferenceData
    ReferenceType
    LongReferenceData
    ReferenceDataExtend
    cbc05eca-a8ae-4f68-869f-38c8fa55864c
    [MasterActivityName]
    29c0310f-bb12-4f85-8362-26995b8c1544
    Activity
    NULL
    And I can see it in Related Activities section on BAM Portal.
    But when I create Relationship in "master" activity and put MessageId to this node (and this MessageId is ActivityId in "detailed" orchestration) then in ActiveRelationships table I see
    ActivityID
    ReferenceName
    ReferenceData
    ReferenceType
    LongReferenceData
    ReferenceDataExtend
    8a2aba6a-4ddb-4932-87d2-f55e33464dcd
    [servername];BizTalkMgmtDb;[DetailActivityName]
    29c0310fcf89ad21-94cd-40e3-b90a-3bdd40e9edad
    MessageId
    NULL
    As you can see there is difference in ReferenceName and ReferenceType columns. And it doesn't appear in Related Activities section.
    How can I use MessageId as key for relation but have type "Activity" instead of "MessageId"?
    I found by experiment If I update this two columns (cut off [servername];BizTalkMgmtDb; from the first one and replace MessageID by Activity for second) then it appear in Related Activities section.
    Thank you in advance for reply!

    But when I create Relationship in "master" activity and put MessageId to this node (and this MessageId is ActivityId in "detailed" orchestration) then in ActiveRelationships table I see......
    I found by experiment If I update this two columns (cut off [servername];BizTalkMgmtDb; from the first one and replace MessageID by Activity for second) then it appear in Related Activities section.
    You can use BizTalk 360 to monitor why this happens, let me know if you have any difficulties.

  • DLL interfacing with mixed value and reference types

    I'm currently trying to work with a supplied DLL.
    I have header files and all, and the DLL import wizard does a decent job of importing the DLL functions but there are some data types which simply can't be handled.
    The DLL requires usage of a data type which is a struct with value and reference data types.  I could theoretically replace the references with simple U32s but much of the required information in the data is in the data structures referenced by the pointers.
    How do I go about implementing this seeing how I need to be able to pass the data back into the DLL in its original form (value and reference types).
    I have something like the following:
    struct Item {
    Int Device,
    *Item Next
    *Item Previous
    *Data Datastruct
    I have downloaded the WDK from Microsoft, have CVI and Visual Studio 2008 available.  I'm not very experienced at this end of things...   I can deal with Structs with pure value types but how do I get at the data in the reference types?
    I strongly suspect I need a wrapper DLL, but how is the best way to go about this?
    Shane.
    Say hello to my little friend.
    RFC 2323 FHE-Compliant
    Solved!
    Go to Solution.

    Hi Shane,
    To be honest, I don't understand why you have to pass the ENTIRE structue (if it's "Item" structure. The pointer to the next and the previous item should be held and manituplated in the DLL, doesn't it?
    Operate within classes....
    Are you talking about Labview Classes? I didn't use it yet. Sorry.
    Convert Linked List to Array You can't store all elements by value in a cluster, because it's kind of recursive. The next pointer leads to the same Item structure (with it's own next pointer. If it's a circulary-linked-list it will never stop)
    Or did you mean to store the pointers as a U32 value? That should work.
    Output the struct as a binary blob Yes, why not ! But that lets me assume you don't know the concrete "Datastructure" ?!
    I'm honest again I can't see the important information you mentioned if you pass the Data structure as a binary blob.
    Read-only is a very good idea. If you don't need to tweak the pointers in the list you should avoid it.
    Balze

  • Reference type in class

    Hi All,
        I am developing report using class.In alv grid  the reference type is like this
       data ref1 type ref to cl_gui_alv_grid
    Now I want for alv list.. what reference type I have use.
    If i Use data ref1 type ref to cl_gui_alv_list it gives error
    please help.
    Thanks,
    Rakesh

    Hi Rakesh,
    If you want your output into list format, just have a look into the following thread:
    Alv using class In list format
    Hope this will help.
    Regards,
    Nitin.

  • Different reference type passed to SubVI

    Hi all,
    I use a subVi to access some properties of an XY graph (scale, offset ...) that's why I use a reference to the graph and give it to the subVI.
    Now I would like to use the same subVI in order to modify the same properties but for an intensity graph.
    Of course when I connect the intensity graph reference to the subVI, the wire gives an error related to incompatible reference type.
    Could someone tell me how I could proceed to connect different reference types to the same subVI input?
    I tried to use "to more generic class" component but I'm not able to find how to use it in this case.
    Thanks in advance for your help

    Hi Fabrice,
    You could place a Case Statement indexed by the type of graph whose properties you want to access / modify, etc.  The reason for mentioning that is the fact that you may not be able to use the same property node for both types of graphs, especuially if you access properties that are not common between the two. 
    There may be tricks that you could try, but as far as using the component "to more generic class", it would have to be located in the calling vi and not the sub-vi.  That is so the same (sub-vi) Terminal can be used.
    However, I am not sure that it would work...  I think I understand what you are trying to do...  I'm not sure if you'll be successful due to the reference types (might be worth a try)..  Nevertheless, if you simply wish to use the same sub-vi for two different graph types, then using the Case Statement will be the quickest solution to implement.
    RayR

  • Behaviour of String as reference type

    I tried this simple code to find out how a String behaves. It does not work as you could expect from a reference type. On the other hand the keyword new is leftout but I expect it is used in the background.
    Can anyone explain !
    Thanks.
    class Te {
    public static void main (String arg[]){
         int[] a = new int [1];
         a[0] = 1;
         int[] b = a;
         a[0] = 2;
         System.out.println("a[0]="+a[0]+" b[0]="+b[0]);
         String c = "AA";
         String d = c;
         c = "BB";
         System.out.println("c="+c+" d="+d);
    And the printout is:
    a[0]=2 b[0]=2
    c=BB d=AA

    I I understand it correctly, the line
    c = "BB";is realy
    c = new String("BB");otherwise c and d should have reference to the same
    String.On some level, yes, but in reality...
    If you know C++, it is should be enough just to say that java's references are really pointers - there are also references in C++ but they mean another things.
    So, c = "BB" just assigns the "reference variable" (pointer) c to a new reference of a String object, but the value of the "reference variable" (pointer) d remains the same. So basicallyString c = "AA";
    String d = c;
    c = "BB";is the same thing asint c = 1;
    int d = 2;
    c = 1;Strings in Java have this nice little extra feature... saying that String c = "BB" and String c = new String("BB") are totally different things. You can check this with code like:String a = "xyzzy";
    String b = "xyzzy";
    String c = new String("xyzzy");
    if (a == b) System.out.println("a and b refer to the same object");
    if (a != c) System.out.println("a and c don't refer to the same object");The literal Strings are stored in a literal String pool, so each occurence of "BB" refers to the same object. But new String("BB") creates a whole new String object, different from the literal "BB".

  • Data type clarification urgent....

    hai there,
    i am not able to use long data type completely in oracle 8i i am able to use only 4000 bytes completely,is ther any configuration to be done before using it.
    plz reply me on [email protected]
    Thanks & Regards
    Kiran

    Duplicate post:
    data type clarification Urgent

Maybe you are looking for