• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

java is pass by value????

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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???
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
simple demo, if it was pass-by-ref, 'list' would change

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Amit Ghorpade
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


[edit]Add code tags. CR[/edit]
[ July 21, 2008: Message edited by: Campbell Ritchie ]
 
suavedeep kaur
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks sir i got my doubt cleared
 
Marshal
Posts: 68098
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Tell me how it all turns out. Here is a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!