There is no concept of pointers in Java, but still we get null pointer exceptions. Why?

The premise of the question is wrong, because there is a concept of pointers in Java. They are called references, and the places where they are used differ from some other languages, but they are pointers nevertheless.

In Java, there are only primitive types and reference types. So all non-primitive values are references. A "reference" is defined (JLS 4.3.1) as either a pointer to an object, or the null reference (which is a null pointer, hence the "null pointer exception").

Comments

Popular posts from this blog

Operating System | Best Definition of Opetating System

Umbrella activities in Software Engineering