Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

When java doesn't support pointers why does it throws null pointer exception?

user-image
Question ajoutée par Venkata Lakshmi
Date de publication: 2016/02/24

A reference variable of class which has null reference and is used to access the any object of class, then it will throw null pointer exception.

Object references are nothing but pointers but they are not complex as Pointers.

Lathesh Karkera
par Lathesh Karkera , Java Developer/It Developer , Unikaihatsu Software Pvt Ltd

Pointers are used in Java implementation for references (Oracle JDK is implemented in C++) who develop/implement the language. It is just that pointers are not accessible to developers who use it.

Azizuddin Khan
par Azizuddin Khan , JAVA-Developer , Cisco

Definitely there are pointers in Java and the null pointer error is one of them but they are managed by the JVM. However, you are not required to deal with them "directly" as you do with C++. You create references by delclaring new variables.. They are pointers. When you declare a variable "pointer" then you need to initialize before using this variable.. otheriwse you will get an error.

Rana Pratap
par Rana Pratap , BDS services

At JVM level everything is pointer. but at java programmer only sees this using references.In actual case the pointer in c/c++ is not related to this exception "NullPointException".This is thrown when we try to call null value or references.

Actually, This pointer is not related to c or c++ pointer.In NullPointerException, pointer has dictionary meaning. And when we call any method on null reference then we will get 'NullPointerException' exception.

zakaul haque
par zakaul haque , Associate Analyst , Global Logic Pvt Ltd

Java Objects need references to its handle which points to it in the stack area When these are not referenced it throw NULL pointer Exception.

To point this out to converted C/C++ programmers, they did not carry the C name over, but named it something else. At the JVM level everything is pointers, but as Java programmers only see this when using references, the exception is badly named.

 Java does indeed have pointers. They can have two kinds of values: (a) references to objects, or (b) null. This is the language used in the Specification.

vishal patil patil
par vishal patil patil , Software Devoloper , KCLINK TECHNOLOGIES

To point this out to converted C/C++ programmers, they did not carry the C name over, but named it something else. At the JVM level everything is pointers, but as Java programmers only see this when using references, the exception is badly named.

shahensha burhan mogulluru
par shahensha burhan mogulluru , JAVA DEVELOPÉR , ICUBE IT SERVICES PVT LTD

We don't use pointers in java. But internal implementation of JVM uses pointers.  When you allocate memory for an object by calling new, you get back a pointer.

Kamran Ali Siddiqui
par Kamran Ali Siddiqui , Programmer , Infocomm Group LLC

Java internally handle pointers but java does not let programmer handle pointers that is the reason Java throws null pointer exception.

Thanks

More Questions Like This