1

I come from C/C++.

When can I speak about pointers in Java? When about references? Can I say that a variable of type Object holds a reference to some data, ie. to an instance of a class? That this variable points to a class' instance?

If Java is always copy by value, then if I pass that beforementioned variable to a function as a parameter, while the variable itself is getting copied, the content of it is still a reference to the class' instance, so that by any practical means it wasn't really a copy by value, as the instance of the class has not been copied, but the reference was, right?

What do Java developers get annoyed to listen to when speaking with C/C++ developers in this context?

It's somehow a hard to formulate question, I hope I managed to get the point across.

Update To reformulate: Can I speak feely about references and pointers using the meaning I learned while learning C/C++ and rest assured that Java developers are picking up the same meaning I'm putting into it?

Update 2 So would it be correct to asume that the word "pointer" is meaningless / should not be used in Java?

Daniel F
  • 13,684
  • 11
  • 87
  • 116
  • @notanormie - Nope. In Java, everything is *pass by value* . Even references to objects are passed by value – TheLostMind Apr 08 '15 at 11:14
  • 1
    possible duplicate http://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value – notanormie Apr 08 '15 at 11:14
  • Yes, I forgot to exclude primitives, thanks for pointing this out. But leaving them aside, I think you know what I mean. So you're calling them pointers? Is it really a pointer or is it a copy of the Java Object which points to the class' instance? In C it would be a 32/64 bit address which gets copied. – Daniel F Apr 08 '15 at 11:17
  • @DanielF it's basically the same only that this adressing is internal and done by JVM it's adress that points to instance. – notanormie Apr 08 '15 at 11:18
  • So I can speak feely about references and pointers using the meaning I learned while learning C/C++ and rest assured that Java developers are picking up the same meaning I'm putting into it? – Daniel F Apr 08 '15 at 11:20
  • Java tried to avoid the many pointer issues that were seen with C. In fact, Java does not provide any means for pointer arithemetics. The usual term for that (in the Java world) is _reference_ as it is simply the more abstract term. As a beginning, you should use that. – Seelenvirtuose Apr 08 '15 at 11:28
  • http://programmers.stackexchange.com/questions/141834/how-is-a-java-reference-different-from-a-c-pointer – cy3er Apr 08 '15 at 11:31
  • @cy3er So the word pointer isn't used in Java? – Daniel F Apr 08 '15 at 11:35
  • @DanielF yes, also they are not exactly the same. Of course, java developers will understand it, it's just not the right word in that context. – cy3er Apr 08 '15 at 11:41
  • @cy3er Then, since in Java a reference is an object that points to / references another object, the word pointer could just be discarded, but if used, it can be used interchangeably with the word reference? – Daniel F Apr 08 '15 at 11:46

1 Answers1

0

It wil be easier to grasp, if you first understand what is kept where in memory (Stack vs Heap), as you have minimal control over memory management compared to C++. Once that's out of the way, it will be easier to understand what's value and what's reference type and how pass by value and pass by reference works. Java is strictly pass by value, but not every data type is a value type. I hope that helps. This is a good start: http://www.journaldev.com/4098/java-heap-memory-vs-stack-memory-difference

Palcente
  • 625
  • 2
  • 7
  • 21