2

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?

8
  • 5
    Admittedly, it could have been named: NullReferenceException... Commented Aug 10, 2012 at 12:56
  • @Aashish - legacy name may be as Java is written in C/C++? Commented Aug 10, 2012 at 12:56
  • 1
    and C doesn't have a NULL pointer exception. that's truly unfair :P Commented Aug 10, 2012 at 12:57
  • Related: stackoverflow.com/questions/7436581/… Commented Aug 10, 2012 at 12:59
  • 1
    @sylvainulg sure it does, it is just named "segmentation fault" or similarly. Commented Aug 10, 2012 at 13:04

5 Answers 5

5

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 ->.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

Object references are nothing but pointers but they are not complex as Pointers. Have a look at this for difference.

Comments

1

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.

Comments

0

It's a carryover from java's "C" herritage. It's also the parlance of the trade.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.