This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Parameter passing

 
Tutu Upadhyay
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!
Actually i was a bit confused regarding the approach that java follows regarding passing objects as parameters....is it by value or by reference??
I am preperaing for SCJP1.4 and could'nt find a reasonable explanation so far. Would be obliged if u could give a detailed explanation.
Thanx!
regards..
Shambhavi.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

Java passes all parameters by value -- but to understand this fully, you have to remember that all objects are referenced via pointers, and it's the pointers, not the objects themselves, that are passed by value when a parameter is an object type.

For a more detailed explanation with examples, please read this and then this.
 
Mahesh Bhatt
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to clear ur doubt in a shortcut ...remember this ...."in , java, all parameters are passed by value, that is, an actual parameter is eveluated and its value is assigned to the corresponding formal parameter . in a tabular format it would be as below

when its a
Primitive data types(int, byte, etc) then its Primitive data value(value ..note that)


when its a
Class type then its a reference value

when its a

array type then its a reference value
[ September 16, 2004: Message edited by: prashant bhogvan ]
 
Mahesh Bhatt
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u said u were preparing for certification .... if u r refering the book "khalid mughal and rass....." ...then looking at the diagrams at pages between 86-93 ...willl clear all your doubts in this matter

bye ...
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!