I am been having a great curiosity.
I have written some java code & it is showing Null Pointer Exception. I am curious to know Why java gives Null Pointer Exception even if it does not support pointers?
I am been having a great curiosity.
I have written some java code & it is showing Null Pointer Exception. I am curious to know Why java gives Null Pointer Exception even if it does not support pointers?
the fact that there's no pointer arithmetic doesn't mean there's no pointer used in the language. And when it comes to Java, there is a lot of pointers, you just follow references with .
rather than with ->
.
Object references
are nothing but pointers but they are not complex as Pointers
. Have a look at this for difference.
Java does support pointers (which you use everytime you have a .
or a [
).
It doesn't support pointer arithmetic - i.e. the ability to manipulate a pointer into another pointer using math.
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.
Java pointers are however much more akin to Pascal pointers than to C pointers.
It's a carryover from java's "C" herritage. It's also the parlance of the trade.