This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How arrays and primitives are passed as parameters in java

 
Mintoo Jaiswal
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How arrays and primitives are passed as parameters in java please explain in detail
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its got to be in the FAQ by now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic