Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: 'pass by value' and 'pass by reference'

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile 'pass by value' and 'pass by reference'

    Hi all,
    I have one doubt in java that is

    what is 'pass by value' and 'pass by reference' ?
    how both use in java..


  2. #2
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts
    Thanks and Regards
    Dan Brown

    Common Java Mistakes

  3. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Re: 'pass by value' and 'pass by reference'

    Tanx For ur replay . if u have the gmail please add me to ur gtalk list . lets be in contact

  4. #4
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Re: 'pass by value' and 'pass by reference'

    Thanks and Regards
    Dan Brown

    Common Java Mistakes

  5. #5
    Member
    Join Date
    Jan 2011
    Location
    Phoenix
    Posts
    49
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: 'pass by value' and 'pass by reference'

    ok i am confused...

    what about arrays?

    if:

    int i[] = {1};

    and i pass it to a method and the method changes it, the actual array is changed. so after the initial change in a method, if that method exits and another method calls the same array, what is stored in the array is what the previous method changed it to, not the original. I was always told that that was passing by reference, help please.

    thanks

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: 'pass by value' and 'pass by reference'

    Quote Originally Posted by that_guy View Post
    ok i am confused...

    what about arrays?

    if:

    int i[] = {1};

    and i pass it to a method and the method changes it, the actual array is changed. so after the initial change in a method, if that method exits and another method calls the same array, what is stored in the array is what the previous method changed it to, not the original. I was always told that that was passing by reference, help please.

    thanks
    Did you read the tutorials you were given? Basically, the thing that's being passed by value is a reference to the array. The tutorials explain it quite well, so I won't go into it further here.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. how to pass a variable from a method to another
    By amr in forum Java Theory & Questions
    Replies: 1
    Last Post: November 20th, 2010, 10:32 PM
  2. Can't pass to the other method
    By mingming8888 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 27th, 2010, 09:44 AM
  3. Replies: 0
    Last Post: April 17th, 2010, 08:29 AM
  4. How do you pass an Array as a Parameter?
    By Arius in forum Java Theory & Questions
    Replies: 1
    Last Post: January 23rd, 2010, 09:36 PM
  5. How to Pass unlimited Arguments to a Function
    By neo_2010 in forum Java Programming Tutorials
    Replies: 2
    Last Post: July 8th, 2009, 11:39 AM