• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Parameter passing

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ...
reply
    Bookmark Topic Watch Topic
  • New Topic