Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Java have pointers?

Tags:

java

pointers

If Java does not have pointers, then what does the the new keyword do in Java?

like image 541
aruna Avatar asked Apr 13 '10 12:04

aruna


1 Answers

As pointed out, Java has references. How are these different ?

  1. you can't perform arithmetic or other such operations on these
  2. they do not point to the memory containing the object (i.e. they are not pointers by another name). The JVM is at liberty to move objects around within the VM memory, and most likely will do during garbage collection. The references however still point to that object, despite its movement within memory.

So they're not like C++ references (pointing directly to an object). Perhaps a better name would be handle.

like image 156
Brian Agnew Avatar answered Sep 27 '22 23:09

Brian Agnew