Article 65 - Java Pass By Value or By Reference Revisited

Recently, it has been a hot topic debating why Java is neither pass by value nor by reference.

This article extends Article 5 - Are Java Functions Pass By Value or By Reference?, you may wish to read that first.

To support the argument, we first look at a C++ function that pass by value and then another that pass by reference, and then constrast it with Java methods.

C++ Pass By Value Function

In C++, pass by value means to duplicate the variable's content onto the stack from memory.

We will discuss in context of the given struct Object declaration.

struct Object

When we invoke the function c_pass_by_value() with the Object struct, the structure's content is copied onto the stack.

c_pass_by_value() function

Within the function, anything we change is visible only in the copied structure, the original is preserved.

c_pass_by_value() example

Constrast this to the Java's method in the following example. Given the java_method(), we invoke it with the Object to see it's effect.

java_pass_by_value() example

C++ Pass By Reference Function

When we invoke the function c_pass_by_reference() with the Object struct, the structure's address is implicitly copied onto the stack.

c_pass_by_reference() function

Within the function, anything we change is visible, even outside the function.

c_pass_by_reference() example

Constrast this to the Java's method in the following example. Given the java_method(), we invoke it with the Object to see it's effect.

java_pass_by_reference() example

Comments (62)

Posted by anonymous - kqjbnonsdt at Sunday, March 24, 2013 9:44 PM

Jf2rTe <a href="http://ymewppllosdn.com/">ymewppllosdn</a>, [url=http://wbuaedtzvobt.com/]wbuaedtzvobt[/url], [link=http://ndrsroonubtc.com/]ndrsroonubtc[/link], http://gnrcjadmydys.com/

Posted by anonymous - fzhxnyf at Tuesday, March 26, 2013 4:40 AM

H503sK <a href="http://djhxttjexqsf.com/">djhxttjexqsf</a>, [url=http://lfwqluulzzpa.com/]lfwqluulzzpa[/url], [link=http://ificwwsalqtf.com/]ificwwsalqtf[/link], http://fkqvnwxtvkin.com/

Posted by anonymous - Red Peep Toe Shoes at Wednesday, March 27, 2013 10:38 AM

I'm not sure why but this website is loading very slow for me. Is anyone else having this issue or is it a problem on my end? I'll check back later and see if the problem still exists. Red Peep Toe Shoes http://allredpeeptoeshoes.webs.com/

Posted by anonymous - swtor credits at Thursday, March 28, 2013 4:00 PM

I do consider all of the ideas you've introduced to your post. They're very convincing and will definitely work. Still, the posts are too quick for beginners. May just you please extend them a little from subsequent time? Thanks for the post. swtor credits http://www.mmogm.com/swtor/

Posted by anonymous - Burberry Outlet at Friday, March 29, 2013 1:49 PM

wonderful post, very informative. I wonder why the other specialists of this sector do not realize this. You must proceed your writing. I'm sure, you've a great readers' base already! Burberry Outlet http://burberryoutlet.v5s7.com

Post a comment

  • Name:
  • Post:
  • Challenge:

Register or login to post comments easier.


Vantasy World Copyright 2011 - 2017. Vantasy World is a project developed by Vantasy Online. Privacy Policy.