Originally posted by geet kaur: guys why don't we have pointers in java?like c++ i have tried to understand it many a times but still confused about this.. can any one explain??
A very general explanation: Pointers directly allow you to manipulate memory. If you are allowed to manipulate memory, then it may lead to destructive programs. Hence they are not allowed in Java for security reasons. In C++, you can use pointers to reclaim memory and sometimes may lead to memory leak since you do it manually. In Java you have the garbage collector which does this automatically and minimizes the risk of memory leak and hence you can concentrate on the application programming rather than memory considerations/optimizations. [ October 21, 2008: Message edited by: Paul Somnath ]
Pointers are hard. Probably most of the bugs in programs written in C or C++ are related to the use of pointers - for example, you're using a pointer that's not initialized properly to point to an object in memory, or you are using a pointer that isn't valid anymore (because the object to which it points has already been deleted).
Pointers are not really necessary, as Java (and other languages that don't have pointers) have proven. The designers of the Java language decided to not include pointers to make Java easier to use.