File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How arrays and primitives are passed as parameters in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How arrays and primitives are passed as parameters in java" Watch "How arrays and primitives are passed as parameters in java" New topic
Author

How arrays and primitives are passed as parameters in java

Mintoo Jaiswal
Greenhorn

Joined: Jul 22, 2005
Posts: 8
How arrays and primitives are passed as parameters in java please explain in detail
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
It's important to know all types are passed exactly the same way, by value. That means the JVM makes a copy of the parameter and the called method sees the copy.

If we pass a primitive things are pretty simple. The JVM makes a copy of the primitive and the argument contains the copy. If you change the value of an argument you change the copy, not the original.

When we pass an object the JVM makes a copy of our variable and the method sees the copy. But what is our variable? It's a pointer to an object. So the method gets a copy of the pointer, not a copy of the object.

Does that help?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

Its got to be in the FAQ by now.
 
Don't get me started about those stupid light bulbs.
 
subject: How arrays and primitives are passed as parameters in java