In JAVA, When an object is passed to a method, the object’s data is copied into a method parameter.
If this is false can you tell me why?
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.
In JAVA, When an object is passed to a method, the object’s data is copied into a method parameter.
If this is false can you tell me why?
In java, almost every parameter is passed by values, however objects are NOT.
They are passed by reference, so the data is not copied into a method parameter.
For more details, check this out: Parameter passing in Java - by reference or by value?
application context
Last edited by daniel.j2ee; December 13th, 2011 at 05:03 PM.
mmm, kind of. Technically everything is pass by value, but when you "pass an object" it's the objects address which gets passed by value.
ex.:
If java did pass a true pass by reference, the first print statement would print 5 instead of 3. However, since the memory address is passed by value, doIt() creates a new array and assigns a to point to that new array, leaving the original val reference unchanged. In doIt2(), a is initialized to refer to the same object as val, so making changes to a results in changes to the same object val points to since it's the same object.
The website you linked to points this distinction out.
Recommended reading: JavaRanch Campfire - Cup Size: a Story About Variables and its follow up JavaRanch Campfire - Pass By Value, Please
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!
And more reading Does Java pass by reference or pass by value? - JavaWorld
Well dear tripline.....if you want to know that concept in-depth then i would recommend you Stanford University's chanel on youtube and in that you have to look for The Programming Methodologies by Mehron Sami.....All you need for that is a fast internet connection.
Hope that help's you in understanding the concept.
Regards,
Ashishkumar Haldar.