0

Pointer in Java

why does java omit the pointer?

2nd Apr 2018, 6:23 PM
Zulfakar
Zulfakar - avatar
3 Respostas
+ 1
Java does have pointers. Any time you create an object in Java, you're actually creating a pointer to the object; this pointer could then be set to a different object or to null, and the original object will still exist (pending garbage collection). What you can't do in Java is pointer arithmetic. You can't dereference a specific memory address or increment a pointer. Unlike C/C++ where pointers are variables which explicitly store memory addresses, and which can be modified arithmetically to point to any arbitrary address java doesn't have that capability. It enhances security we can say.
2nd Apr 2018, 9:19 PM
SatyaJit Pradhan
SatyaJit Pradhan - avatar
+ 7
Java doesn't give the programmer direct access to memory, therefore no pointers no malloc no free no realloc etc. This is done for safety reasons, it protects the programmer from tampering with things (in Java's mind at least) they shouldn't.
2nd Apr 2018, 6:39 PM
Rusty.Metal
2nd Apr 2018, 6:26 PM
sayan chandra
sayan chandra - avatar