ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

In java why we don't use pointer?

If we use pointer then in which way we used

user-image
تم إضافة السؤال من قبل Aman Shrivastava
تاريخ النشر: 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
من قبل 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
من قبل 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.

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟