IT Community - Software Programming, Web Development and Technical Support

difference between call by value and call by reference

This is a discussion on difference between call by value and call by reference within the Java Programming forums, part of the Software Development category; hi there, i was totally confused with the concept call by value and call by reference...i dont find any ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Java Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 09-18-2007, 12:33 AM
amansundar amansundar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 325
amansundar is on a distinguished road
Default difference between call by value and call by reference

hi there,
i was totally confused with the concept call by value and call by reference...i dont find any idea of using either by call by reference or call by value..in which situation i need to use these unique concept..plz someone explain with sample...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-18-2007, 01:13 AM
leoraja8 leoraja8 is offline
D-Web Sr.Programmer
 
Join Date: May 2007
Posts: 194
leoraja8 is on a distinguished road
Default Re: difference between call by value and call by reference

look at the j2me sample below..
Code:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;


public class sample extends MIDlet 
{
    static int a=10,b=20;
    
    public void startApp()
    {
        swap(a,b);
        System.out.println("a :"+a);
        System.out.println("b :"+b);           
    }    
    public void pauseApp()
    {
    }
    public void swap(int a,int b)
    {       
        int t=a;
            a=b;
            b=t;
    }
    public void destroyApp(boolean unconditional) 
    {
    }
}
in this output value for a and b is same as declared and swap(int a,int b) got no influence over a and b.....
this concept of method calling is known as call by value...if slight changes made in swap() method as below
Code:
 public void swap(sample s)
    {       
             int t=s.a;
            s.a=s.b;
           s.b=t;
    }
the output value for a and b was interchanged...this type of method calling is call by reference..by this example u can
find the difference between those two concept

Last edited by leoraja8 : 09-18-2007 at 01:30 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-18-2007, 01:34 AM
amansundar amansundar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 325
amansundar is on a distinguished road
Default Re: difference between call by value and call by reference

thanks a lot buddy..
__________________
cheers
Aman
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
call xml elements in php Vani Sri PHP Programming 11 03-11-2008 06:29 AM
How to call PHP functions from ASP.net? $enthil ASP and ASP.NET Programming 1 02-14-2008 08:04 PM
Function call and System call vigneshgets Operating Systems 1 08-01-2007 06:18 AM
How Do I Call Java from C? kingmaker C and C++ Programming 1 07-30-2007 07:58 AM
How can I call system in C? Sabari C and C++ Programming 1 07-17-2007 03:57 AM


All times are GMT -7. The time now is 11:26 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0