0

No Pointers in Java

Do pointers exist in Java? This is an interesting and debatable comment. To be precise in answering, “NO!”.

Java does not support pointers. Instead, it uses references. Instead of pointing to a memory location, Java refers to an object’s methods/members only. This facilitates the garbage collection feature to run robustly as well. Because if Java had been supporting pointers, then the GC would have to figure out a way to trace all the pointers. In C++ if the memory location is moved around, then we need to make sure that any other part of the program if was pointing to that memory, so it gets hard and tricky. If this is not handled well, dereferencing¬†might give junk or bad data and would lead the program to crash. Pointers also are a threat to a program’s security. Viruses and hacking programs can be developed using pointers. So Java developers have willingly eliminated pointers to provide a secure environment and a steady approach.

ayesha

Leave a Reply

Your email address will not be published. Required fields are marked *