This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes java is  pass by value???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java is  pass by value????" Watch "java is  pass by value????" New topic
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
simple demo, if it was pass-by-ref, 'list' would change

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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: 2716
    
    6

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: 2716
    
    6

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: 38075
    
  22
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java is pass by value????
 
Similar Threads
Passed!!
Passed
Passed By Reference?
Passed. :)
Passed