Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

In java why we don't use pointer?

If we use pointer then in which way we used

user-image
Question added by Aman Shrivastava
Date Posted: 2013/11/09

The term "pointer" is strongly associated with the C/C++ concept of pointers, which are variables which explicitly store memory addresses, and which can be modified arithmetically to point to any arbitrary address. In Java, pointers exist, but not as a first-class language concept. Rather, pointers only exist as an implementation detail for References. The spec says:

 

An object is a class instance or an array.

 

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

 

It's also telling that accessing a null reference throws a NullPointerException, not a NullReferenceException. So, clearly the Java designers were at least thinking in terms of pointers when they wrote the Java language spec. (Although really it should be called a NullReferenceException; in my opinion the name of that exception leaks through the abstraction)

ajay deepak
by ajay deepak , software developer , IBM India

Java does not support pointers which deals with memory directly , where in java takes care of memory allocation automatically , so you dont worry about using pointers

Ajith Fernandez
by Ajith Fernandez , Software Engineer , Nayasoft Solutions Pvt.ltd

Pointer is reference handle to memory location. Improper handling of pointer leads to memory leakage and reliablity issues hence java doesn't support usage of pointer.

This was an intentional decision by the creators of Java, because most people would agree that having pointers creates a lot of potential for bugs in the code – pointers can be quite confusing, especially to new programmers. If you need to use pointers, use objects.

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.