Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are Java 'pointers' integers?

I am taking data structures and analysis. We have gone over how assignment and comparisons of object types is much slower than assignment and comparisons for basic types, such as int.

I recall learning C (all those almost thirty years ago) and how pointers in C are (or were) integer calls. Is Java similar today, is a reference to an instanced object internally an integer address of memory, and as such are comparisons such as

if (MyObject != null) {...}

an integer operation within the framework?

I hope my question is clear. I've been researching around and I can't find a clear answer of how Java manages its dynamic memory.

like image 468
failure Avatar asked Oct 20 '22 14:10

failure


1 Answers

The short answer is yes, a reference to an object is stored as pointer like it is in C.

I am not sure what you mean by stored as "integer", but if what you want is to do some operation on them like you can do in C (e.g. add integer to a pointer, etc.), then you can't with Java.

For the rest, it's pretty much the same except that it is handled by Java.

JLS 4.3.1 specifies that a reference to an object is stored as pointer:

The reference values (often just references) are pointers to these objects, and a special null reference, which refers to no object.

like image 60
Jean-François Savard Avatar answered Oct 29 '22 00:10

Jean-François Savard