Author
java is pass by value????
suavedeep kaur
Ranch Hand
Joined: Jun 02, 2008
Posts: 36
i am confused about the java 's concept of pass by value ............as some books say java is all pass by value and some says Primitive types are passed by value and Objects are passed by reference please can someone explain in detail whats the reson n how it happens???
Suavedeep kaur
SCJP
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted Jul 21, 2008 00:38:00
0
simple demo, if it was pass-by-ref, 'list' would change
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12907
Welcome to JavaRanch. Yes, Java is pass by value only. But the confusing thing is that references are also passed by value. For more information, see this JavaRanch Campfire Story: Pass-by-Value Please
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Amit Ghorpade
Bartender
Joined: Jun 06, 2007
Posts: 2547
Hi suavedeep kaur welcome to Javaranch,
i am confused about the java's concept of pass by value ............as some books say java is all pass by value and some says Primitive types are passed by value and Objects are passed by reference
In which book did you find that Objects are passed by reference It's actually object references are passed by value and not objects. Hope this helps
SCJP, SCWCD.
|Asking Good Questions |
Amit Ghorpade
Bartender
Joined: Jun 06, 2007
Posts: 2547
And yes
as some books say java is all pass by value
Why only some books all books say so. Hope this helps
suavedeep kaur
Ranch Hand
Joined: Jun 02, 2008
Posts: 36
sir f have complete reference its on page 133 i am new to java so exploring it its what all is written objects are passed by value
suavedeep kaur
Ranch Hand
Joined: Jun 02, 2008
Posts: 36
[edit]Add code tags. CR[/edit] [ July 21, 2008: Message edited by: Campbell Ritchie ]
suavedeep kaur
Ranch Hand
Joined: Jun 02, 2008
Posts: 36
Thanks sir i got my doubt cleared
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
Originally posted by suavedeep kaur:
Thanks sir i got my doubt cleared
Well done. This is a common problem, and causes quite a lot of confusion, particularly when some books are not precise in how they describe it. Click the search button above, and put "pass by value" in the box. You get lots of links; try this one , and look at the "wonderful link" quoted in the 3rd message. It is a bit complicated, but explains very clearly what pass-by-reference would be and how in works in Pascal. You can then try it out in Java, as in Michael Dunn's example, and you can see how the results are different.
subject: java is pass by value????