Why doesn't Java have pointers?

Quora Feeds

Active Member
Joshua Engel

True pointers would make JVM verification impossible. The JVM verifier makes certain guarantees about a class file: the stack won't overflow, private variables will remain private, initializers are always initialized, etc.

This was touted most prominently in the domain of applets, where JVM programs could be downloaded without any possibility of misbehavior, but it's important even on the applications side. Many optimizations can be performed because the absence of pointers means that you can make guarantees about the value of something: values cached, redundant operations eliminated, thread safety guaranteed, etc.

True pointers also make garbage collection impossible. A piece of memory referenced only by its location cannot be moved to make larger contiguous blocks of memory available. The memory picture can become fragmented, and it can be impossible to allocate even though in aggregate plenty of memory is available.

Most valid uses of pointers in C have some corresponding construct in Java, and the ones that aren't can generally be worked around in some way. The designers of Java (and I) consider it a fair tradeoff for the benefits of a memory management system that far less prone to memory leaks, over-eager memory releases, and the mysterious and hard-to-trace crashes that plague pointer-based programming languages.

See Questions On Quora

Continue reading...
 
Top