IC5Notice: We have upgraded developerWorks Community to the latest version of IBM Connections. For more information, read our upgrade FAQ.
Topic
  • 3 replies
  • Latest Post - ‏2011-11-16T02:43:12Z by dev1008
SumitTrehan
SumitTrehan
2 Posts

Pinned topic How does an Object is returned in Java vs C?

‏2011-09-07T04:36:31Z |
Hello experts,

I have a doubt that how does an object is returned by a method in Java.

Inferences for above statement:
In C we know that the memory allocated locally inside a function will vanish when the function returns



char *getName() 
{ 

char name[]=
"Sumit"; 

return name 
}


The caller of the function will get a pointer to the array.Although the pointer points a garbage unknown location since the array was local, it has now been destroyed.

Now I have a doubt the same thing works in Java

{code}
public String getName()
{
String name="Sumit"; //name here is local as above;memory allocated for the object locally
return name;
}

The caller of the method will correctly get the desired String passed.

Now my question is How the pointer (or reference in Java) is returned when it is compared to C.
Hope I made my points clear

Hoping to get a reply soon
Regards
Updated on 2011-11-16T02:43:12Z at 2011-11-16T02:43:12Z by dev1008
  • todd12
    todd12
    1 Post

    Re: How does an Object is returned in Java vs C?

    ‏2011-11-08T06:38:05Z  
    can we use the concept of applets here for using the graphical terms to make it more attractive or not,according to me the object is called through a class or method in java and also returned through calling the objects with the class

    ______________________
    http://www.canamlimo.com/toronto-airport-limo.html
  • seohulu
    seohulu
    8 Posts

    Re: How does an Object is returned in Java vs C?

    ‏2011-11-14T20:05:50Z  
    there aren't pointers from the java programmer's perspective, only references, in your example, there are no way for caller to grab the address of "submit", the caller has to have his own reference to receive the "submit" value ,like this "String callersRef = getName();"

    Acoolme is an Online Marketing Software Platform And Social Community
  • dev1008
    dev1008
    2 Posts

    Re: How does an Object is returned in Java vs C?

    ‏2011-11-16T02:43:12Z  
    • todd12
    • ‏2011-11-08T06:38:05Z
    can we use the concept of applets here for using the graphical terms to make it more attractive or not,according to me the object is called through a class or method in java and also returned through calling the objects with the class

    ______________________
    http://www.canamlimo.com/toronto-airport-limo.html
    Dear Friends....

    How you are post your query because i would like post my new Question in this forum. Can you please help me on this. From where we can post new topic. Your early response is always appreciated.
    Thnx
    Rahul