This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Parameter passing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Parameter passing " Watch "Parameter passing " New topic

Parameter passing

Tutu Upadhyay

Joined: Sep 13, 2004
Posts: 1
Actually i was a bit confused regarding the approach that java follows regarding passing objects as 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.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189


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.

[Jess in Action][AskingGoodQuestions]
Mahesh Bhatt
Ranch Hand

Joined: Sep 15, 2004
Posts: 88
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 ]

Impossible is I M Possible
Mahesh Bhatt
Ranch Hand

Joined: Sep 15, 2004
Posts: 88
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 ...
Have you checked out Aspose?
subject: Parameter passing
It's not a secret anymore!