Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.
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.
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.
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.
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.
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.
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.
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.
Java internally handle pointers but java does not let programmer handle pointers that is the reason Java throws null pointer exception.
Thanks